Docker

Updating

docker compose pull
docker compose up --force-recreate --build -d
docker image prune -f

Zsh completions

Create the script and store it

mkdir -p ~/.docker/completions
docker completion zsh > ~/.docker/completions/_docker

Add the following to .zshrc

FPATH="$HOME/.docker/completions:$FPATH"
autoload -Uz compinit
compinit

Shell execution

This requires the container to have a shell installed. docker ps can get the id of the container.

docker exec -it <container> sh

Secrets

Secrets must be used on the manager in a docker swarm cluster

Create a new secret

printf "my super secret password" | docker secret create my_secret -

Shell history should be cleared so that the password is not visible there if reading from stdin. Alternatively, you can read the password from a file through the method below

docker secret create my_secret ./secret.json

Pruning

Images not in container

docker image prune -a

Containers

Removes all stopped containers

docker container prune

Docker stack

Switch to another docker context

docker context use {context_name}

Deploy services from a compose file

docker stack deploy --compose-file docker-stack.yml {service_name}