Keep Calm and Learn Golang

Useful Docker Commands

These were just some useful docker commands I thought I’d jot down so I wouldn’t forget them. This is a fairly short list, so fair warning: I’m publishing it to embarrass myself into making it longer and more useful.

Exposing ports:

docker run -p hostPort:containerPort

See other formats here: Needs an EXPOSE in the docker file for container port

Listing containers (two ways – second is more “canonical”)

docker ps -a
docker container ls -all

List all volumes, images, etc.

docker volume ls

Danger Zone

Stop and remove all containers on the machine

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

Similarly to remove all volumes:

docker volume rm $(docker volume ls -q)