Docker Cheat Sheet

Docker Cheat Sheet

CommandDescriptionExamples
docker runRun an image in a container.$ docker run -it ubuntu /bin/bash
docker psList all running containers.$ docker ps
docker stopStop a running container.$ docker stop my-container
docker rmRemove a stopped container.$ docker rm my-container
docker rmiRemove an image from the Docker Hub registry.$ docker rmi ubuntu
docker loginLog in to your Docker Hub account.$ docker login <your-username> <your-password>
docker buildBuild a new image from a Dockerfile.$ docker build -t my-image .
docker commitCreate a new image based on an existing one and push it to the registry.$ docker commit my-container >my-image
docker tagTag an image with a different name.$ docker tag my-image <new-name>
docker loginLog in to your Docker Hub account.$ docker login <your-username> <your-password>
docker network createCreate a new network.$ docker network create my-network
docker network connectConnect a container to a network.$ docker network connect my-container >my-network
docker network disconnectDisconnect a container from a network.$ docker network disconnect my-container <my-network>
docker volume createCreate a new volume.$ docker volume create my-volume
docker volume lsList all volumes.$ docker volume ls
docker volume rmRemove an existing volume.$ docker volume rm my-volume
docker run --rmRun a container in detached mode and automatically remove it when the process exits.$ docker run -it –rm ubuntu /bin/bash
docker execExecute a command inside a running container.$ docker exec -it my-container bash
docker stopStop a running container.$ docker stop my-container
docker rmRemove a stopped container.$ docker rm my-container
docker rmiRemove an image from the Docker Hub registry.$ docker rmi ubuntu
docker system prunePrunes all unused containers, images, and cache.$ docker system prune
docker container inspectInspect a property of the container.$ docker container inspect -f ‘{{.HostConfig.LogConfig}}’ <id>