Skip to main content

Installing Docker

3.1. Ready to Install? Let's Go!​

Well, since you already know what a container is and what Docker is all about, it's time to get your hands dirty. Let's install Docker for the first time!

The Docker daemon runs natively on Linux distributions, which is why installation on non-Linux operating systems basically consists of spinning up a VM and running the daemon from there. The client, however, can be installed on the major operating systems currently available.

Installing Docker on Linux machines is quite simple. We just need to observe a few points:

  • Docker does not support 32-bit processors.

  • Docker is supported (stable) only on kernel version 3.8 or higher.

  • The kernel must support the file systems used by Docker, such as AUFS, Device Mapper, OverlayFS, etc.

  • The kernel must support cgroups and namespaces, which is normally enabled by default on most distros.

You can also visit the URL: https://docs.docker.com/install/. There you can learn how to install Docker on various Linux distributions, on major clouds, and also on MacOS and Windows.

In this book we'll use the Ubuntu Linux distribution, but it doesn't change much for other distributions. Enough talking, let's go!

First, let's check the kernel version to see if it's compatible with Docker:

# uname -r

3.2. Installing on Debian/CentOS/Ubuntu/SUSE/Fedora​

Installing Docker is quite simple. You can choose to install it using the packages available for your distro -- for example, apt-get or yum.

We prefer to do the installation by running the curl command below, which will execute a script and detect which distribution we're using, and then add the official Docker repository to our package manager, rpm or apt, for example.

# curl -fsSL https://get.docker.com/ | sh

This way it will always fetch the latest version of Docker. :)

3.3. Installing 'Manually' on Debian​

If you're using Debian and want to perform the installation using the packages available in the repository, do:

# apt-key adv --keyserver \
hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

Now let's create/edit the "/etc/apt/sources.list.d/docker.list" file and add the repository address corresponding to your Debian version. In our case, we're using Debian version 8, also known as Jessie.

# vim /etc/apt/sources.list.d/docker.list # Debian Jessie

deb https://apt.dockerproject.org/repo debian-jessie main

After adding the previous line, it's necessary to update the repository list by running:

# apt-get update

After finishing the update of the available repository list, we can now install Docker. The package name is "docker-ce". :)

# apt-get install docker-ce

Let's check if Docker is running. Type the following on the command line:

# /etc/init.d/docker status

Or:

# service docker status

docker container stop/waiting

With this, we can verify if the process is running. As we can see, the Docker daemon is not running, so let's start it.

# service docker start
docker container start/running, process 4303

# service docker status
docker container start/running, process 4303

Perfect! Now we have Docker installed and ready to start playing with containers. \o/

3.3.1. Important Tip​

By default, the Docker daemon binds to a Unix socket, not to a TCP port. Unix sockets, in turn, are owned by and for exclusive use of the root user (which is why Docker is always started as root), but can also be accessed via sudo by other users.

To avoid having to keep using sudo when running Docker commands, create a group called docker and add your user to it. Stop the service and start it again.

Unfortunately, not everything is rosy. This procedure means that the user has the same privileges as the root user in operations related to Docker. More information at the link: https://docs.docker.com/engine/security/.

To create a group on Linux and add a user is no secret, just run:

sudo usermod -aG docker user

Million-dollar tip: user = your username. :D