September 21, 2018 Docker Cheat Sheet

Some useful Docker and Docker Compose commands

Actions with Docker containers

list all running containers

docker ps

list all containers

docker ps -a

stop all active containers

docker stop $(docker ps -q)

stop all containers

docker stop $(docker ps -a -q)

remove all containers

docker rm $(docker ps -a -q)

remove all containers with status=exited

docker rm $(docker ps -q -f status=exited)

view logs from container

docker logs -f <container_name>

Actions with Docker images

list all images

docker images

delete all images

docker rmi -f $(docker images -q)

Docker tips and tricks

docker detailed space usage

docker system df -v

show container IP

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_id

shell into docker container

docker exec -it container_id /bin/bash

Docker Compose

build docker containers

docker-compose build

start docker compose

docker-compose up -d

start docker compose with build

docker-compose up -d --build

stop docker compose

docker-compose down

Stop, remove containers, remove images and networks what was created by "docker-compose up"

docker-compose -f docker-compose.yml down --rmi all