Skip to content

Instantly share code, notes, and snippets.

@lincolnaleixo
Last active September 18, 2024 21:28
Show Gist options
  • Save lincolnaleixo/08151856937d29cb84a18c55bfad1c1b to your computer and use it in GitHub Desktop.
Save lincolnaleixo/08151856937d29cb84a18c55bfad1c1b to your computer and use it in GitHub Desktop.
docker aliases
# Attach a docker
alias da="docker attach"
# Get latest container ID
alias dl="docker ps -l -q"
#This should free up quite a lot of disk space usually.
#it removes unused images.
alias dip="docker image prune"
# it removes unused containers.
alias dcp="docker container prune"
# it removes unused volumes.
alias dvp="docker volume prune"
# Get container process
alias dps="docker ps"
# Get process included stop container
alias dpa="docker ps -a"
# Get images
alias dim="docker images"
# Get container IP
alias dip="docker inspect --format '{{ .NetworkSettings.IPAddress }}'"
# Run deamonized container, e.g., $dkd base /bin/echo hello
alias dkd="docker run -d -P --name"
# Run interactive container, e.g., $dki base /bin/bash
drun() { docker run -d -it $1 ; }
# Run deamonized and interactive container, e.g., $dkdi base /bin/echo hello
alias dd='dcuf && dpa'
alias ddd='dcufd && dpa'
#get logs in real time
alias dlr='docker logs -f'
alias dkdi="docker run -it -d -P --name"
alias dex="docker exec -i -t"
# Bash into running container
dbash() { docker exec -it $(docker ps -aqf "name=$1") bash; }
alias dcs="docker compose stop"
# Stop and Remove all containers
alias drmf='docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)'
# Stop and Remove all containers and images
alias drmfi='docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q) && dri'
# Stop all containers
dstop() { docker stop $(docker ps -a -q); }
# Start all containers
dstart() { docker start $(docker ps -a -q); }
# Remove all containers
drm() { docker rm $(docker ps -a -q); }
# Remove all images
dri() { docker rmi -f $(docker images -q); }
# Stop and delete a container
dsr() { docker stop $1 && docker rm $1 ; }
# Delete an image
dir() { docker image rm $1 ; }
# docker compose up -d --scale api=3
dcus() { docker compose up -d --scale $1=$2; }
# Dockerfile build, e.g., $dbu tcnksm/test
dbu() { DOCKER_BUILDKIT=1 docker build --compress -t=$1 .; }
dbuf() { DOCKER_BUILDKIT=1 docker build --compress -t=$1 -f=$2 .; }
dbuc() { docker build --compress --no-cache -t=$1; }
alias dcb="docker compose build"
alias dcu="docker compose up -d"
alias dcd="docker compose down"
alias dcuf="docker compose up -d --force-recreate"
alias dcbuf="docker compose build && docker compose up -d --force-recreate"
alias dcbufnc="docker-compose build --no-cache && docker-compose up -d --force-recreate"
alias dcbufncs="dri && drm && docker-compose build --no-cache && docker-compose up -d --force-recreate --scale api=3"
alias dcbd="docker-compose -f docker-compose.dev.yml build"
alias dcud="docker compose -f docker-compose.dev.yml up -d"
alias dcdd="docker compose -f docker-compose.dev.yml down"
alias dcufd="docker compose -f docker-compose.dev.yml up -d --force-recreate"
alias dcbufd="docker compose -f docker-compose.dev.yml build && docker compose up -d --force-recreate"
alias dcbufdnc="docker-compose -f docker-compose.dev.yml build --no-cache && docker-compose -f docker-compose.dev.yml up -d --force-recreate"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment