Docker is a containerization technology that allows you to quickly build, test and deploy applications as portable, self-sufficient containers that can virtually run everywhere.
I recently installed Docker CE on a 64-bit CentOS 7 machine and I thought I’d post an article about the process I followed. I’m going to keep this short and sweet without going into too much detail. You should be able to follow these instructions to install Docker CE on CentOS 7 or any Red Hat family machine. This tutorial assumes that you installing Docker on a freshly spun up machine with NO previous versions of Docker installed. If there have been previous versions of Docker, it is recommended that you uninstall the old version before installing Docker again. You should also have non-root user with sudo privileges.
There are 3 steps to installing Docker CE – Community Edition on CentOS 7
1. Updating your OS and Linux Kernel (if necessary),
2. Install Docker
3. Assign Administrator Privileges
Check Kernel version and update CentOS 7 OS
First we will quickly check the kernel version just to make sure that your kernel version does meet with the requirements for running Docker – Kernel 3.10 is the absolute minimum kernel version that supports the features that Docker requires to run stable (the newer versions are obviously preferred). As at the time of this writing, the latest stable release of the Linux Kernel was 4.20, so if you kernel version is version lower than this, it is highly recommended that you upgrade or install the latest version. One important aspect of installing Docker is the knowing how to use Storage Drivers. They are responsible for the building and storage of images and how these are used. You can follow this link for more detailed information https://docs.docker.com/storage/storagedriver/overlayfs-driver/ Ideally your CentOS 7 should have kernel version 4.0 or higher so that you can take advantage of the
overlay2 driver which is also supported by the Docker EE (premium Enterprise Edition). If your kernel version lower than 4.0 you may want to have a look at this article which explains how to upgrade or install to the latest version How to Install or Upgrade to latest Kernel in CentOS 7
Docker likes to run on an up-to-date system – so next we run this command to update our Operating System.
The package manager will refresh the package list and see where an upgrade is available. As soon as it is ready it will ask to apply the updates:
The following command will ensure that you install the very latest version of Docker from the Official Docker Repository.
Once the command has executed you should notice towards the end of the output, you’ll find the following – take note of the
sudo usermod -aG docker your-user on line 5. You will need to run that command to assign administrative rights to your username.
Then we need to enable Docker Engine,
And finally after starting Docker-Engine, we will have completed the installation of Docker.
Now you can run your first Docker Command at the command prompt to verify that Docker Engine has started and is running.
Assign Administrator Privileges
Once we have confirmed that Docker is running, the next step is to assign administrator privileges. Docker by default requires administrator privileges. In order to run Docker commands without prepending “sudo” run the following command and afterwards log out and log back in again. Make sure to replace
your-user with your username.
Next you’ll want to verify that you can run commands without prepending “sudo”. This command will also pull the “Hello World” image from the Docker Hub Repository and since we using the
docker run command, it will also run the image and create a container.
This command will list all your images.
See a list of all your containers, running or not
View all the commands that are available to use with Docker
You should register at the Official Docker Registry https://hub.docker.com/. From here you will be able to pull images which in turn you can be run as containers. You can modify these images and use them to create your own images. I highly recommend that you only pull and use images from Official, Verified Publishers or Docker Certified images.
Now that you have Docker installed on your CentOS 7 machine and know how to download Docker images and manage Docker containers. You may also want to read about Docker Compose, which allows you to define and run multi-container Docker applications.
This tutorial barely scratches the surface of the Docker ecosystem. In some of our next articles, we will continue to dive into other aspects of Docker. To learn more about Docker check out the official Docker documentation. Once you start using Docker on a regular basis, it will change the way you view your current development process.