My Docker Patterns
These are some docker commands that I use enough to want to share. I’m not saying they are optimal (or modern), but I use the following commands regularly.
Reset Local Docker
Sometimes, you just want to start fresh.
# Remove all containers docker rm -f $(docker ps -aq) # Remove all images docker rmi -f $(docker images -aq) # Remove all volumes docker volume rm -f $(docker volume ls -aq)
This will build along with start the containers. The
--build flag will save you a
command if you care about busting the build cache if there were changes (ie, code
changing that you then want updated in the container).
docker-compose up --build
See container env vars
It’s useful to see what environment variables are set in a container.
Quick and easy using a JSON array dump of env variables:
docker inspect 85331d6894cd | less # then / to search for `"Env`
docker inspect 85331d6894cd| jq '..Config.Env'
If you have
rq and want fancy columnar output to use with an
docker inspect CONTAINER_ID_HERE |\ jq '..Config.Env' |\ sed 's/^ "//' |\ sed -E 's/",?$//' |\ column -t -s=