Docker Cheatsheet This note was created on 5/5/2023 This note was last edited on 5/5/2023 === Images === List all images available on your Docker host: > docker images Download a specific Docker image from a registry: > docker pull *image-name* Build a Docker image from a Dockerfile: > docker build -t *image-name* /path/ === Containers === List all running containers: > docker ps Start a new container from a Docker image: > docker run *image-name* Start an existing container: > docker start *container-id* Stop a running container: > docker stop *container-id* Remove a stopped container: > docker rm *container-id* Connect to container: > docker exec -it *container-id/container-name* /bin/sh === Networks === List all Docker networks available on your host: > docker network ls Create a new Docker network: > docker network create *network-name* Connect a container to a network: > docker network connect *network-name* *container-id* Disconnect a container from a network: > docker network disconnect *network-name* *container-id* === Volumes === List all Docker volumes available on your host: > docker volume ls Create a new Docker volume: > docker volume create *volume-name* Inspect details of a specific Docker volume: > docker volume inspect *volume-name* Remove a Docker volume: > docker volume rm *volume-name* === Logs === Fetch the logs of a container: > docker logs *container* Follow the logs of a container: > docker logs -f *container* Display last N lines of the logs: > docker logs --tail N *container* Show extra details provided by logs: > docker logs --details *container* Add timestamps to the logs: > docker logs --timestamps *container* === Compose === Start all containers defined in a Docker Compose file: > docker-compose up Stop and remove all containers defined in a Docker Compose file: > docker-compose down View logs of all containers defined in a Docker Compose file: > docker-compose logs === Dockerfile === ~~~ FROM Base image MAINTAINER Author name RUN Run a command CMD Default command EXPOSE Expose a port ENV Set an environment variable ADD Copy files or directories COPY Copy files or directories ENTRYPOINT Entrypoint script ~~~