Skip to content

Instantly share code, notes, and snippets.

@DeepInThought
Created May 30, 2019 07:51
Show Gist options
  • Save DeepInThought/5dac7c0f6bfff456622039877614f549 to your computer and use it in GitHub Desktop.
Save DeepInThought/5dac7c0f6bfff456622039877614f549 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#file: ~/.docker/docker_lib_functions.sh
#? REF: https://dev.to/argherna/bash-functions-and-aliases-for-the-beginning-docker-developer-d4
# Runs Docker build and tag it with the given name.
#
docker_build_tag() {
if [ $# -lt 1 ]; then
echo "Usage $FUNCNAME DIRNAME [TAGNAME ...]"
return 1
fi
ARGS="$1"
shift
if [ $# -ge 2 ]; then
ARGS="$ARGS -t $@"
fi
docker build $ARGS
}
# Run a bash shell in the specified container.
#
docker_exec_bash() {
if [ $# -ne 1 ]; then
echo "Usage: $FUNCNAME CONTAINER_ID"
return 1
fi
docker exec -it $1 /bin/bash
}
# Run a bash shell in the specified container (with docker-compose).
#
docker_compose_exec_bash() {
if [ $# -ne 1 ]; then
echo "Usage: $FUNCNAME CONTAINER_ID"
return 1
fi
docker-compose exec $1 /bin/bash
}
### Docker Security Functions ###
#? See https://github.com/docker/docker-bench-security
docker_security_bench_run() {
docker run --rm -it --net host --pid host --userns host --cap-add audit_control \
-e DOCKER_CONTENT_TRUST=$DOCKER_CONTENT_TRUST \
-v /etc:/etc \
-v /usr/bin/docker-containerd:/usr/bin/docker-containerd \
-v /usr/bin/docker-runc:/usr/bin/docker-runc \
-v /usr/lib/systemd:/usr/lib/systemd \
-v /var/lib:/var/lib \
-v /var/run/docker.sock:/var/run/docker.sock \
--label docker_bench_security \
--name docker_bench_security \
docker/docker-bench-security $1
}
###################################
#EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment