Docker Cheatsheet

Running containers

Run container:

docker run

Run container in daemon mode:

docker run -d

Run container in daemon mode and set name:

docker run -d --name <name_of_container>

Process

Show docker processes:

docker ps

Images

Search of Images:

docker search <image_name>

Pull images from repo:

docker pull <image_name>

Show local images:

docker images

Remove docker images:

docker rmi <image_name>

Force remove docker images:

docker rmi -f <image_name>

Build

Build docker container from docker file:

docker build -t <docker_file>

Build container but do not start the container:

docker start <docker_file>

Container interaction

Basic command for interaction:

docker exec

Connect to interactive shell for a container

docker -exec -i -t <container_name>

docker -exec -it <container_name>

Network

Display docker networks:

docker network

Create docker network:

docker network create <network_name>

Remove docker network

docker network rm <network_name>

System

Remove all stopped containers, dangling images and unused networks (basically cleanup)

docker system prune

Secrets

Create secrets that can be passed to docker:

docker secret create <secret_name> <file_name>

Quick Remove

Remove all containers from server with one line:

docker service rm $(docker service ls -q)

Resources

Last updated