A while ago, we have published a guide on how to install Docker on Ubuntu. Today, we will see how to install Docker in CentOS Linux operating system. In addition, we will also see how to install Docker compose, a tool to define and run multi-container Docker applications.
Even though, this guide is specifically written for CentOS, this guide is same for other RPM based distributions like Fedora, RHEL, Scientific Linux, and openSUSE etc.
Install Docker In CentOS
To install Docker on CentOS, your system must meet the following minimum requirements.
- 64 bit architecture;
- the Kernel version should be 3.10 or above.
- Your system should be connected with Internet.
Docker installation is fairly simple and straight forward.
Open your Terminal and run the following command as
# curl -fsSL https://get.docker.com/ | sh
After installing Docker, run the following commands to enable and start Docker service.
# systemctl enable docker
# systemctl start docker
Check whether Docker service is running or not with command:
# systemctl status docker
Sample would be something like below.
● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2017-03-08 14:09:38 IST; 24s ago Docs: https://docs.docker.com Main PID: 1190 (dockerd) Memory: 54.4M CGroup: /system.slice/docker.service ├─1190 /usr/bin/dockerd └─2327 docker-containerd -l unix:///var/run/docker/libcontainerd/d... Mar 08 14:09:35 server1.ostechnix.local dockerd: time="2017-03-08T14:09:3... Mar 08 14:09:35 server1.ostechnix.local dockerd: time="2017-03-08T14:09:3... Mar 08 14:09:35 server1.ostechnix.local dockerd: time="2017-03-08T14:09:3... Mar 08 14:09:36 server1.ostechnix.local dockerd: time="2017-03-08T14:09:3... Mar 08 14:09:37 server1.ostechnix.local dockerd: time="2017-03-08T14:09:3... Mar 08 14:09:38 server1.ostechnix.local dockerd: time="2017-03-08T14:09:3... Mar 08 14:09:38 server1.ostechnix.local dockerd: time="2017-03-08T14:09:3... Mar 08 14:09:38 server1.ostechnix.local dockerd: time="2017-03-08T14:09:3... Mar 08 14:09:38 server1.ostechnix.local dockerd: time="2017-03-08T14:09:3... Mar 08 14:09:38 server1.ostechnix.local systemd: Started Docker Application ... Hint: Some lines were ellipsized, use -l to show in full.
As you see above, Docker service is running!
Let us go ahead, and test whether Docker is working or not.
To do so, run:
# docker run hello-world
The above command will download a test Docker image, and execute a sample hello_world program inside the container.
If you see an output something like below, congratulations! Docker is working fine in our CentOS system.
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 78445dd45222: Pull complete Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/
To check the Docker version, run:
# docker version
Client: Version: 17.03.0-ce API version: 1.26 Go version: go1.7.5 Git commit: 60ccb22 Built: Thu Feb 23 10:54:03 2017 OS/Arch: linux/amd64 Server: Version: 17.03.0-ce API version: 1.26 (minimum version 1.12) Go version: go1.7.5 Git commit: 60ccb22 Built: Thu Feb 23 10:54:03 2017 OS/Arch: linux/amd64 Experimental: false
That’s all for now. Docker is ready to use.
Install Docker Compose
Docker Compose is a tool that can be used to define and run multi-container Docker applications. With Compose, you use a Compose file to configure your application’s services. Then, using a single command, you can create and start all the services from your configuration.
We can install Docker Compose using any one of the following methods.
Run the following command from the Terminal as
root user to download Docker Compose binary file:
# curl -L "https://github.com/docker/compose/releases/download/1.11.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Then, apply executable permissions to the binary using command:
# chmod +x /usr/local/bin/docker-compose
Alternatively, we can install Docker Compose using PIP. Pip is a python package manager used to install applications written in Python programming language.
On Arch Linux and its derivatives, run the following command to install pip:
# sudo pacman -S python-pip
On Debian, Ubuntu, Linux Mint:
# sudo apt-get install python-pip
On RHEL, Fedora, CentOS:
# sudo yum install python-pip
# sudo dnf install python-pip
# sudo zypper install python-pip
Once pip installed, run the following command to install docker compose. The following command is same for all Linux distributions!
# pip install docker-compose
After installing Docker Compose, you can check the version with command:
# docker-compose --version
You will see an output something like below.
docker-compose version 1.11.2, build dfed245
We now know how to install Docker and Docker Compose in CentOS. Read the following article to getting started with Docker.
Download Free Docker Ebooks:
Download - Free Guide: "Understanding Docker"
Download - Free Guide: "Introduction to Docker"
Download - Free Guide: "Docker in Production"