I have read a lot of guides on how to use Docker and lot of them start explaining Docker complicated way. From writing Dockerfiles and with docker-compose. The goal of this article is to explain Docker the easy way, such that someone can use it as soon as possible. I mean, at the end, Docker is just yet another tool and we should not spend rest of our lives masteerring it.

So, here we go:

Docker container vs Docker image

In short, Docker images are like classes, like base systems etc.. They are immutable and they cannot be changed in any way. They are “as it is”. On the other hand, containers are instances of images. They can be changed (its file system structure for instance).

Every container can expose some ports, share file system structure with host etc….

Basic commands to get you started ASAP

The most minimalistic image is busybox. It is image which requires very small amount of memory and other resources but it comes with few tools with limited functionality. Just basic UNIX commands and nothing more. Let’s create container from that image:

docker run --name example -it busybox

so, in run command, we create container with name “example” and run it. You can see that we did not specify command which will be executed on container. If we do not specify command, default command for image will be executed (in this case: /bin/sh). We also pass interactive flag (-i) to enable binding to host stdout, stderr and stdin. Also, we pass -t flag to emulate pseudo-tty.

you can specify explicitly command like this:

docker run --name example -it busybox /bin/sh

More complex images can be found at https://hub.docker.com/

Now, when we have started container, we can see it running by executing:

docker ps 

To execute new command in already running container, call:

docker exec example your-command

To enable interactive and ptty mode (for /bin/bash for instance), you can specify -it flag.

Now, when was container starter? Well, when we have run docker run. This command creates and starts container immediately.If we want step by step process, it would go like this:

docker create –name someImage
docker start myContainer
docker exec -it myContainer bash

Also, you can create image from existing container (such that it can be used to make other containers):

docker commit myccontainer myimage:latest

and also you can publish image to Docker Hub such that community can use it.

When you create image, you can put it into tarball to send to a friend and restore it from tarball

docker save mmyImage > myImage.tar
docker load < myImage.tar

Conclusion

This was very short article to get you started using docker without need to write your own Dockerfile. You can search Docker Hub for already existing images.

Good luck and happy development. :)