Mon aide-mémoire Docker – Docker cheat sheet

Docker

docker psList running containers
docker imagesList docker images
docker exec -it <container_id> bashLaunch 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 buildBuild application (when run in directory with docker-compose.yml)
docker-compose upRun application
docker-compose up -dRun application detached from console
docker-compose stopStop application
docker-compose run django bashLaunch 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