Installing Docker on CentOS

What is Docker

Docker is a container system. It allows you to run multiple applications or services on the same server in a manner that isolates them from each other. This allows you to run, for example, multiple versions of your application on the same server without conflicts.

Docker also makes your application very portable. You essential create an image of your application, which contains all required binaries and files, and deploy that image onto other servers. Since all required binaries are included in the image, you no longer have to spend time downloading and installing the required packages each time you deploy your app. This saves you or your operations team a lot of administrative time.

Another benefit is Docker registries. Think of these like version control and package repositories for your entire application stack. When I say version control, I don’t mean for the code for your application. It means you can maintain multiple configurations for your image, each with different versions of the required packages that run your app. For example, you could have two Docker images for your application, one running Java 6 and another running Java 7. Your production servers can run the Java 6 version of your Docker image. When you are comfortable your new Java 7 build is production ready, you simply swap the Java 6 Docker image with the Java 7 Docker image. If something serious is discovered with your Java 7 config, you can just as easily swap back in the Java 6 image. How’s that for time savings and efficiencies?

Speaking of efficiencies, containerization allows you to increase the density of services running on your physical hardware. I don’t want you to confuse this with Docker being a replacement for virtualization – it’s not. Instead, it allows you to pack in more services onto your hardware without wasting resources on additional operating system installs. Think about all of the storage and memory wasted on twenty full installation of CentOS running a different applications. These applications are usually separated for a reason, whether that be for security, politics or minimizing package or service conflicts. With Docker, you can run all twenty applications on a single server.

Installation

Installing Docker on CentOS 6

Docker is not available in the default CentOS 6 repositories. To install it you will need to add the EPEL repository to your server.

  1. Install and enable the EPEL respository
    rpm -iUvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
  2. Install Docker IO
    yum install -y docker-io

 

Installing Docker on CentOS 7

Unlike earlier versions of CentOS, Docker is now available in the CentOS 7 default repositories. Other than yum installing Docker, there are no additional steps.

  1. Install Docker
    yum install -y docker-io

Running Docker

Docker runs as a system service. Before you can create and run Docker images, you will first need to start its service. If you expect the service to always be available, you will need to instruct CentOS to start it at boot time.

The following instructions are for CentOS 6. However, if you run them in CentOS 7 the commands will automatically be mapped to a SystemD equivalant.

  1. Start the Docker service.
    service docker start
  2. Configure Docker to automatically start during system boot.
    chkconfig docker on