Mon aide-mémoire Docker – Docker cheat sheet


docker ps List running containers
docker images List docker images
docker exec -it <container_id> bash Launch a shell in a running container
docker rm <container_id> Remove container
docker rmi <image_id> Remove image
docker stop $(docker ps -a -q) Stop all containers
docker rm $(docker ps -a -q) Remove all containers

Build a docker image named « web » using a Dockerfile found in current directory (« . »)

docker build -t web .

Same as above but disable cache to force a complete rebuild

docker build --no-cache=true -t web .

Docker CLI reference


Docker Compose

docker-compose build Build application (when run in directory with docker-compose.yml)
docker-compose up Run application
docker-compose up -d Run application detached from console
docker-compose stop Stop application
docker-compose run django bash Launch a shell in the container named django

Compose CLI reference


Docker Machine

Create dev machine

docker-machine -D create -d virtualbox dev

Create production machine (on DigitalOcean)

docker-machine -D create -d digitalocean --digitalocean-region=fra1 --digitalocean-access-token=<token> production

Set shell environment to use dev machine

eval "$(docker-machine env dev)"

You can now run any docker or docker-compose commands on your machine

Unset shell env variables

eval "$(docker-machine env -u)"

Docker machine