Docker cheatsheet

Containers

Getting started
# Create and run a container from an image, with a custom name:
docker run --name <container_name> <image_name>
# Run a container with and publish a container’s port(s) to the host.
docker run -p <host_port>:<container_port> <image_name>
# Run a container in the background
docker run -d <image_name>
ExampleDescription
docker psList running containers
docker ps -aList all containers
docker exec -it <container> bashConnecting to container
docker logs <container>Shows container’s console log
docker start/stop <container>Start or stop a container
docker kill <container>Kill a container
docker restart <container>Restart a container
docker rm <container>Remove a container

Images

Images
# Build an Image from a Dockerfile
docker build -t <image_name>
# Build an Image from a Dockerfile without the cache
docker build -t <image_name> . –no-cache
# List local images
docker images
# Delete an Image
docker rmi <image_name>
# Remove all unused images
docker image prune
ExampleDescription
docker psList running containers
docker ps -aList all containers
docker exec -it <container> bashConnecting to container
docker logs <container>Shows container’s console log
docker start/stop <container>Start or stop a container
docker kill <container>Kill a container
docker restart <container>Restart a container
docker rm <container>Remove a container