Share via


DevOps Basics: Introduction to Docker Commands and Concepts

In continuing this DevOps Basics series, it is now time to learn the basic commands to properly enable use of Docker.

Introduction and Quick Concepts

I don’t want to go very deep on the containerization’s concepts but here some important concepts to understand with Docker / Containers by the simplest way.

  • Let’s keep that simple and say: Container = Image (same wording)

  • A Docker Registry is a public or private store which contains images

  • An image run thanks to the Docker’s daemon

  • The Docker’s daemon can be installed on any OS (Windows, Mac or Linux)

  • You can run multiples images with the same daemon (in the same OS)

  • Your images could or couldn’t talk between each other;

In terms of architecture, we can simply resume something like this:

Our containers (C), run on the top of a VMs running the Docker daemon inside any OS hosted on physical hosts or a cloud provider.

Is it working?

The best way to check if your Docker environment working is, through your command line, run a simple:

docker --version

You should be able to see this :

At the moment of I’m writing this blog post ,the latest version is the 1.10.3, you can check this information on the official GitHub repo: https://github.com/docker/docker

Hello World

The classic “Hello World” is a good way to try and test your environment.

You can try with this simple command:

docker run hello-world

As you can see, the first message that we had is: Unable to find image ‘hello-world’ locally

It’s important to understand what Docker did with this command:

  1. He checked if the image called ‘hello-world’ was already there on the local environment

  2. If not, he checked the public repository call: Docker Hub : https://hub.docker.com/

  3. He pulled (Download) the image locally

  4. And finally run this image locally

Understanding the lifecycle of your containers

After our awesome “Hello-world” test, we want to check more about our process.

One of the basic command to do that is : docker ps -a

Is important to add the switch “-a” to catch all the process, even the stopped one.

You can see here, our “hello-world” image have an “Exited…” status. That mean this image is stopped with nothing running on it.

To see the difference you can check a simple : docker ps

As you can see the difference, without the “-a” switch, you will be able to see only the running containers.

Now we can try to re run a second time: docker run hello-world :

We have the same output, and if we check again our process with : docker ps -a :

We have now two different process, with a different NAMES and CONTAINER ID with the same IMAGE.

If you remembered well my first architecture diagram in the introduction, you should be able to understand that each time we do a: “docker run hello-world” we are creating a new container, in fact a new “C’ purple square in the diagram, inside our VM.

Name your containers

As you can see each time we do a docker run command, Docker is generating and assigning a random name to this one.

If we want to determine by our self this name we can add the command : --name MyContainerName after the docker run command :

The logical thing is that you cannot have two time the same name for one container, you will have a conflict:

Remove your containers

You just have to execute the following command: docker rm CANITPRO

You can also do the same command using only the first characters of the container id : docker rm a61ebec

Conclusion

We just started to discover the basics of the Docker command and play with the Hello-World container.

In the next article we will discover more about "Ports Mapping", "Volume Mapping", "Registry" and even more…