Container – Docker Containers are what docker is built on. They encapsulate an application and all of its libraries and dependencies, so it can be run anywhere Docker is installed.

Image – A Docker Image is a file that is essentially a snapshot of a container. You can create a container by running a Docker Image.

Layer – a set of read-only files to provision the system. Think of a layer as a read only snapshot of the filesystem.

Registry / Hub is the central place where all publicly published images live. You can search it, upload your images there and when you pull a docker image, it comes the repository/hub. You can also create private docker registry in your own cloud.

Docker machine is a VM within which you can run Docker containers. On Linux you can run docker containers natively, but on OSX and Windows you need a layer of abstraction. A docker machine will spin a very lightweight virtual machine that integrates with the docker command line utilities really well.

Docker compose is a utility to run multiple containers as a system of containers. It will take care of making them aware of each other and ensure they’re properly connected to each other. This means you can run your application in one container and your database in a different container, and your analytics application in a different container, and so on. This is the ultimate isolation and it means that your applications are independent and are run in development in a very similar way to how the system might work in production.

Docker Cheat Sheet examples

Create and start container, run command

docker run -it --name <container_name> <image> -d

Start, stop and restart the container

docker [start|stop|restart] <container_name> or <container-id>

Use docker attach to attach to a running container using the container’s ID or name, either to view its ongoing output or to control it interactively.

docker attach <container_name>

Kill all running containers

docker kill $(docker ps -q)

Delete dangling images the ones that are not tagged properly and are hanging around.

docker rmi $(docker images -q -f dangling=true)

Remove all stopped containers, this will actually try to remove all the containers, but will fail to do so with the running ones, so only stopped containers will be gone after that.