Skip to content

Instantly share code, notes, and snippets.

@jamesslomka
Last active January 23, 2021 18:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesslomka/87cd8eea58e4ebc42c66c74de3d9eeb9 to your computer and use it in GitHub Desktop.
Save jamesslomka/87cd8eea58e4ebc42c66c74de3d9eeb9 to your computer and use it in GitHub Desktop.
# Important that you set the path to the folder where your docker-compose.yml lives
#
# e.g. Documents/Git/workspace
DOCKER_COMPOSE_PATH=''
# ---------------DOCKER/DOCKER COMPOSE:-------------------
# Runs a docker command of your choice from anywhere.
#
# Usage: dc <command>
dc() {
docker-compose --project-directory ~/$DOCKER_COMPOSE_PATH -f ~/$DOCKER_COMPOSE_PATH/docker-compose.yml $@
}
# Docker-compose restart
dcr() {
dc kill "$1"
dc up -d "$1"
}
# Docker Compose Logs.
#
# Inspect the logs in real-time of a container by name.
# Defaults to all containers if no name is specified.
#
# Usage: dcl
# Usage: dcl <name>
dcl() {
dc logs --tail "100" -f "$1"
}
# Docker-compose restart logs - will restart container and bring up its logs
dcrl() {
dc kill "$1"
dc up -d "$1"
dcl "$1"
}
# Docker stop all running containers
alias dsa='docker stop $(docker ps -a -q)'
alias d='docker'
alias dcu='dc up -d'
alias de='dc exec'
alias dr='d run -it --rm -v $(pwd):$(pwd) -w $(pwd)'
alias dd='d kill $(d ps -a -q); d rm $(d ps -a -q)'
alias dp='d ps -a'
alias purgeDocker='d kill $(d ps -a -q); d rm $(d ps -a -q); d volume rm $(d volume ls -q); d network rm $(d network ls -q)'
alias purgeDockerImages='d rmi -f $(d images -f dangling=true -q)'
# Docker Cleanup.
# Deletes all containers and images.
#
# Usage: dcleanup
dcleanup() {
docker rm $(docker ps -q -f 'status=exited')
docker rmi $(docker images -q -f "dangling=true")
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /etc:/etc spotify/docker-gc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment