How to install and validate Docker CE and Docker Compose on CentOS
Here in this article we will try to install and setup Docker CE (Community Edition) and Docker Compose on centos 7 machine. Here we are going to install Docker CE and Docker Compose using RPM package.
Test Environment
CentOS 7 64-bit version
What is Docker
Docker is a platform designed to help developers build, share, and run container applications. We handle the tedious setup, so you can focus on the code.
What is Docker Compose
Docker Compose is a tool for defining and running multi-container docker applications. It uses a compose file to define services for your application. Using a single command you can create and start all services defined in the compose file.
Procedure
Step1: Docker Setup
Let’s now see how we can install docker service on centos linux system.
Step1.1 Download RPM packages
Here in this step we are going to download the following packages for the centos repository as shown below.
URL - https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
Packages:
docker-ce-17.03.1.ce-1.el7.centos.x86_64.rpm
docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch.rpm
Step1.2: Install the docker-ce-selinux RPM package
Let’s now install the docker-ce-selinux package as shown below.
sudo yum install docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch.rpm
Step1.3: Install the docker-ce RPM package
Now let’s install docker-ce package as shown below.
sudo yum install docker-ce-17.03.1.ce-1.el7.centos.x86_64.rpm
Step1.4: Verify the docker installation
Once the required packages are installed we can verify the installed docker version as shown below.
docker --version
Output:
Docker version 17.03.1-ce, build c6d412e
Step1.5: Start the Docker service
It’s time to start the docker and enable service startup on reboot as shown below.
sudo systemctl start docker
sudo systemctl enable docker
Step1.6: Run the hello-world docker image
Let’s now verify our installation by running a sample “hello-world” docker image as shown below.
sudo docker run hello-world
Output:
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/
Step1.7: Location of images, containers, volumes or customised configuration files
Here is the default location of images, containers and volumes that are stored for the docker containers.
sudo ls -ltr /var/lib/docker/
Output:
total 8
drwx------. 4 root root 30 Jun 14 03:07 plugins
drwx------. 3 rootroot 20 Jun 14 03:07 image
drwx------. 2 root root 24 Jun 14 03:07 volumes
drwx------. 2 root root 6 Jun 14 03:07 trust
drwxr-x---. 3 rootroot 18 Jun 14 03:07 network
drwx------. 2 root root 6 Jun 14 03:07 swarm
drwx------. 2 root root 6 Jun 14 03:07 tmp
drwx------. 7 root root 4096 Jun 14 03:08 overlay
drwx------. 4 root root 4096 Jun 14 03:08 containers
Step2: Docker Compose Setup
Next, let us now setup Docker Compose as show below.
Step2.1: Download the Docker Compose binary
Here we will download the docker compose binary from the following location and save it to “/usr/local/bin” directory as shown below.
sudo curl -L https://github.com/docker/compose/releases/download/1.14.0-rc2/docker-compose-Linux-x86_64 > /usr/local/bin/docker-compose
Step2.2: Run docker-compose executable
Running the docker-compose tool without any options should provide you with an help output.
chmod 755 /usr/local/bin/docker-compose
/usr/local/bin/docker-compose
Step2.3: Test the installation
You can verify the version of the docker-compose that is installed as shown below.
docker-compose --version
Output:
docker-compose version 1.14.0-rc2, build 24dae73
Hope you enjoyed reading this article. Thank you..
Leave a Reply
You must be logged in to post a comment.