Common

- CLI documentation:

docker

- Common information:

docker info

- Docker version:

docker version

- Remove unused objects:

docker system prune --all --volumes

- Search image:

docker search hello-world

- Hello world on Docker:

docker run ubuntu /bin/echo 'Hello world'

- Run image as container:

docker run -it alpine /bin/bash

Containers

- Create a container (without starting it):

docker create [IMAGE]

- Rename an existing container:

docker rename [CONTAINER_NAME] [NEW_CONTAINER_NAME]

- Delete a container (if it is not running):

docker rm [CONTAINER]

- Delete all stopped containers:

docker rm $(docker ps -a -q)

- Update the configuration of one or more containers:

docker update [CONTAINER]

- Start a container:

docker start [CONTAINER]

- Stop a running container:

docker stop [CONTAINER]

- Stop all running containers:

docker stop $(docker ps -a -q)

- Stop a running container and start it up again:

docker restart [CONTAINER]

- Pause processes in a running container:

docker pause [CONTAINER]

- Unpause processes in a running container:

docker unpause [CONTAINER]

- Kill a container by sending a SIGKILL to a running container:

docker kill [CONTAINER]

- Kill all containers:

docker kill $(docker ps -a -q)

- Login to container:

docker exec -it [CONTAINER] bash

Images

- Pull an image from a registry:

docker pull [IMAGE]

- Push an image to a registry:

docker push [IMAGE]

- Create an image from a container:

docker commit [CONTAINER] [NEW_IMAGE_NAME]

- Remove an image:

docker rmi [IMAGE]

- Remove all images:

docker rmi $(docker images -q)

For container and image information

- List running containers:

docker ps

- List all containers:

docker ps -a

- List all containers id:

docker ps -a -q

- List the logs from a running container:

docker logs [CONTAINER]

- List the logs from a running container in real-time:

docker logs -f [CONTAINER]

- Show port (or specific) mapping for a container:

docker port [CONTAINER]

- Show running processes in a container:

docker top [CONTAINER]

- Show live resource usage statistics of all containers:

docker stats

- Show live resource usage statistics of specific container:

docker stats [CONTAINER]

- Running containers size:

docker container ls -s

- Show images (also size):

docker images

- Show the history of an image:

docker history [IMAGE]

Networks

- List networks:

docker network ls

- Create network:

docker network create [NETWORK]

- Remove one or more networks:

docker network rm [NETWORK]

- Show information on one or more networks:

docker network inspect [NETWORK]

- Connects a container to a network:

docker network connect [NETWORK] [CONTAINER]

- Disconnect a container from a network:

docker network disconnect [NETWORK] [CONTAINER]

Volumes

- List all volumes:

docker volume ls

- Create the volume:

docker volume create <VOLUME>

- Remove the volume:

docker volume rm <VOLUME>