How To Install Docker Compose on CentOS 7

To Install Docker Compose on CentOS 7

Docker Compose is a tool for running multi-container Docker applications. To configure an application’ s services with Compose we use a configuration file, and then, executing a single command, it is possible to create and start all the services specified in the configuration. In this tutorial, we are going to cover the method to install Docker Compose on CentOS 7.

 

Install Docker

The easiest way to install Docker is by downloading an installation script provided by the Docker project. 

[root@linuxhelp ~]# wget -qO- https://get.docker.com/ | sh


Once it is done, you can just enable and start the docker by making use of the following commands. 

[root@linuxhelp ~]# systemctl enable docker


Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

[root@linuxhelp ~]# systemctl start docker


Install the EPEL repository by executing the following command. 

[root@linuxhelp ~]# yum install epel-release
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
.
.
Installed:
epel-release.noarch 0:7-9                                                     
Complete!


After which you need to install python. 

[root@linuxhelp ~]# yum install -y python-pip
Loaded plugins: fastestmirror, langpacks
epel/x86_64/metalink                                     | 7.2 kB     00:00  
.
Installed:
python2-pip.noarch 0:8.1.2-5.el7                                              
Complete!


At this point, it is possible to install Docker Compose by executing a pip command so do the same as follows. 

[root@linuxhelp ~]# pip install docker-compose
Collecting docker-compose
  Downloading docker_compose-1.18.0-py2.py3-none-any.whl (111kB)
    100% |████████████████████████████████| 112kB 98kB/s
.
Successfully installed PyYAML-3.12 backports.ssl-match-hostname-3.5.0.1 cached-property-1.3.1 certifi-2018.1.18 chardet-3.0.4 docker-2.7.0 docker-compose-1.18.0 docker-pycreds-0.2.1 dockerpty-0.4.1 docopt-0.6.2 enum34-1.1.6 functools32-3.2.3.post2 idna-2.6 ipaddress-1.0.19 jsonschema-2.6.0 requests-2.18.4 texttable-0.9.1 urllib3-1.22 websocket-client-0.46.0

 

Also, you need to upgrade all the Python packages on CentOS 7. 

[root@linuxhelp ~]# yum upgrade python*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
.
python-gobject-base.x86_64 0:3.22.0-1.el7_4.1                                 
python-perf.x86_64 0:3.10.0-693.17.1.el7                                      
Complete!


After that, you need to check the Docker Compose version with the following command. 

[root@linuxhelp ~]# docker-compose -v
docker-compose version 1.18.0, build 8dd22a9

 

After that, you need to test the Docker Compose.   So, let’ s create a new directory and move into it by making use of the following command. 

[root@linuxhelp ~]# mkdir hello-world
[root@linuxhelp ~]# cd hello-world/

 

And then you need to open a .yml file by making use of the following command. 

[root@linuxhelp hello-world]# vim docker-compose.yml
In that file, paste the following content
unixmen-compose-test:
 image: hello-world
Once done, save and exit the file. After that, you need to run the container. 


Next, execute the following command in the hello-world directory. 

[root@linuxhelp hello-world]# docker-compose up
Pulling unixmen-compose-test (hello-world:latest)...
latest: Pulling from library/hello-world
.
.
unixmen-compose-test_1  |  https://docs.docker.com/engine/userguide/
helloworld_unixmen-compose-test_1 exited with code 0

If everything is correct, the above thing   should be the output shown by Compose.  With this, the method to install and test Docker Compose on CentOS 7 and to use the Compose file in the YAML format comes to an end. 
 

Tag : CentOS Docker
FAQ
Q
How to configure Subdomains, Nginx-proxy and Docker-compose?
A
You can just set your nginx to redirect like so:

location /jenkins {
proxy_pass http://jenkins:8080; /> ...
}

location /other-container {
proxy_pass http://other-container:8080; /> }
Q
What is the Efficient way to run a Docker Compose stack in production?
A
docker-compose up -d, all the container options are sent to the Engine and stored. If you specify restart as always (or preferably unless-stopped to give you more flexibility) then you don't need run docker-compose up every time your host boots.When the host starts, provided you have configured the Docker daemon to start on boot, Docker will start all the containers that are flagged to be restarted. So you only need to run docker-compose up -d once and Docker takes care of the rest.
Q
How do I get the Stable or Edge version of Docker for Windows?
A
Use the download links for the channels given in the topic Download Docker for Windows.
Q
How to deploy hyperledger fabric in production level?
A
I think that for a production deployment, you'd likely want to implement Swarm or Kubernetes. See Hyperledger Cello for instance. You will also want to have a process and automation for management.
Q
Do I lose my data when the container exits?
A
Any data that your application writes to disk gets preserved in its container until you explicitly delete the container. The file system for the container persists even after the container halts.