Docker - Notes - Cheat Sheet





Dockerfile defines what goes on in the environment inside your container. Access to resources like networking interfaces and disk drives is virtualized inside this environment, which is isolated from the rest of your system, so you need to map ports to the outside world, and be specific about what files you want to “copy in” to that environment. However, after doing that, you can expect that the build of your app defined in this Dockerfile behaves exactly the same wherever it runs.


$ docker --version

Docker version 18.03, build c97c6d6

$ docker-compose --version

docker-compose version 1.21.0, build 8dd22a9

$ docker-machine --version

docker-machine version 0.14.0, build 9ba6da9


## List Docker CLI commands
docker container --help

## Display Docker version and info
docker --version
docker version
docker info

## Execute Docker image
docker run hello-world

## List Docker images
docker image ls

## List Docker containers (running, all, all in quiet mode)
docker container ls
docker container ls --all
docker container ls -aq

## Stop a container
docker container ls # get CONTAINER ID
docker container stop <CONTAINER ID>

## Remove all containers
docker rm $(docker ps -a -q)

Docker Cheat Sheet

Here is a list of some basic Docker Commands to help you get started with Docker. This helped me a lot and still does from time to time. Note, this not meant to be a complete Docker reference. For complete list, please visit


Pull a base image.
docker pull ubuntu

Start a container
docker run --name docker-nginx -p 80:80 -d nginx
docker run --name docker-nginx -p 80:80 -d -v /app/html:/usr/share/nginx/html nginx

For list of running containers
docker ps

For list of all containers
docker ps - a

Restart a Container.
docker restart container_id

Show all running process in a Container.
docker top container_id

Stop container
docker stop container_id

Remove container
docker rm container_id>

Kill containers and remove them
docker stop $(docker ps -aq)
docker rm $(docker ps -aq)
docker rm $(docker kill $(docker ps -aq))

Clean up old containers that are weeks old (via Stackoverflow)
docker ps --filter "status=exited" | grep 'weeks ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm

Print the last 100 lines of a container’s logs 
docker logs --tail 100 container_id

Create a new bash process inside the container and connect it to the terminal
docker exec -it container_id bash

Docker Container link
Docker run -d -p 5000:5000 --link redis dockerapp:v0.3

Docker Images

Remove all images
docker rmi $(docker images -q) -f
docker rmi $(docker images -qf "dangling=true")

Remove all images except “my-image”
You could use grep to remove all except my-image and ubuntu
docker rmi $(docker images | grep -v ‘ubuntu\|my-image’ | awk {‘print $3’})

Save a running container as an image
docker commit -m "commit message" -a "author" container_id username/image_name:tag

Other Docker Commands

Run commands inside an existing container
docker exec -it [containerID] bash

Push to Images to Docker
docker tag 2f98ca2e63ab docker-nginx:1.01
docker login --username muralibala
docker push docker-nginx:1.01

To find Ip address
docker machine ls

List the networks
docker network ls

List the volumes
docker volume ls

Add comment

Security code