Traditional virtualization technologies provide hardware virtualization, which means they create a complete hardware environment so each virtual machine (VM) needs a complete operating system to run it. Therefore they have some major drawbacks because they are heavyweight and produce a lot of overhead while running. This is where the open-source Docker containerization engine offers an attractive alternative. It can help you build applications in Linux containers, thus providing application virtualization.
This means that you can bundle any Linux program of choice with all its dependencies and its own environment and then share it or run multiple instances of it, each as a completely isolated and separated process on any modern Linux kernel, thus providing native runtime performance, easy portability, and high scalability. Here, in this recipe, we will show you how to install and configure Docker on your CentOS 7 server.
To complete this recipe, you will require a working installation of the CentOS 7 operating system with root privileges, a console-based text editor of your choice, and a connection to the Internet in order to download additional rpm
packages and a test Docker image.
While Docker is available as a package in the official CentOS 7 repository, we will use the official Docker repository to install it on our system instead.
yum update && curl -sSL https://get.docker.com/ | sh
systemctl enable docker && systemctl start docker
docker run hello-world
When installing any software on CentOS 7, most of the time it is a very good advice to use the packages available in your official CentOS repository instead of downloading and installing from third-party locations. Here by installing Docker using the official Docker repository instead we made an exception. We did this because Docker is a very young project and is evolving fast, and it keeps changing a lot. While you can use Docker for running every Linux application, including critical web servers or programs dealing with confidential data, bugs found or introduced into the Docker program can have severe security consequences. By using the official Docker repository, we make sure we always get the latest updates and patches available as fast as possible right from the developers of this fast-moving project. So anytime you type yum update
in the future, your package manager will automatically query and check the Docker repos to see if there is a new version of Docker available for you.
So what did we learn from this experience?
We started this recipe by logging into our server as root and updated the YUM package's database. Then we used a command to download and execute the official Docker installation script from https://get.docker.com/ in one step. What this script does is add the official Docker repository to the YUM package manager as a new package source and then automatically install Docker in the background. Afterwards, we enabled the Docker service at boot-time and started it by using systemd
. Finally, to test our installation, we issued the command docker run hello-world
, which downloads a special image from the official Docker registry to test our installation. If everything went fine, you should see the following success message (output truncated):
Hello from Docker
This message shows that your installation appears to be working correctly.