24 C
Texas
angeloma
Senior Writer and partner

How to install Docker Compose on CentOS 7?

ersionDocker’s technology is one of the most widely used today. Many sysadmins use it to deploy applications quickly and easily through images. These images contain applications or services already “packaged” that can run indistinctly from the system. It is only necessary that the system has Docker installed and that’s it. However, there are tools that extend these features. Therefore, I will teach you how to install Docker Compose on CentOS 7.

As I have already explained, Docker is highly popular. If you did not know, it is an open source technology project that allows the deployment of applications through containers. These containers are distributed in the form of images that are loads from Docker. So, the programmer or Sysadmin can make an image of an application and redistribute it in many systems. In addition, all this without dependencies or compatibility problems.

What is Docker Compose?

Docker Compose was born as a tool that extends the functionality of Docker. Docker is for deploying or installing applications that are in the form of images. However, many applications require other images to run. For example, if you want to install WordPress, you need the images of the web server, the database handler and finally the WordPress itself. This also happens with other services, which require to operate other services.

With Docker Compose it is possible to define the dependencies of an image and they will be automatically managed. Too useful and practice this utility.

- Advertisement -

So, let us install Docker Compose on CentOS 7.

Install Docker Compose on CentOS 7

To use Docker Compose, you need to install Docker first. Installing Docker is quite simple and in this post, we show you how to do it.

Read how to install Docker on CentOS 7?

Once Docker is installed and fully functional, we can start installing Docker Compose.

For this, we will use the official Docker Compose binary. Open a terminal and as root user run the following command:

:~# curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

1.- Download and install Docker Compose
1.- Download and install Docker Compose

After that, set the execution permission to the binary.

:~# chmod +x /usr/local/bin/docker-compose

Next, create a sym link for Docker compose.

:~# ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Finally, check the installed version.

:~# docker-compose --version

2.- Docker compose
2.- Docker compose

So, Docker compose is ready to use.

Using Docker Compose

Docker Compose automatically manages various images through a .yaml file. This file defines the parameters to be followed and the management of the images. Then, it is lifted with a command and ready.

In this example, I will make a file to install a LAMP server.

First, we need to create a file with a .yml extension called docker-compose. On it, we need to put all the image requisites. For example:

version: "3"
 
services:
  test_mysql:
    image: mysql:5.7
    environment:
      - MYSQL_DATABASE=testdatabase
      - MYSQL_ROOT_PASSWORD=rootpss
      - MYSQL_USER=user
      - MYSQL_PASSWORD=userpss
    volumes:
      - ./volume/mysql:/var/lib/mysql
    expose:
      - 3306
    ports:
      - 3306:3306
   
  php:
    image: php:7-apache
    volumes:
      - ./test_web/:/var/www/html
    expose:
      - 80
    ports:
      - 80:80
    links: 
      - test_mysql

3.- Creating the docker-composer yml file
3.- Creating the docker-composer yml file

The file is somewhat long but very understandable. I will try to explain it briefly to make it clearer.

Version refers to the version of the Docker Compose file. It is currently 3. As it evolves, it becomes incremental. Within Service, the services to be deployed are defined. In this case, there are two, MySQL and PHP with Apache already incorporated.

The first service is MySQL where test_mysql is the name of the service and the image that is going to load. Then, we define an environment with test credentials. We need to create a new volume so as not to lose the data and make it available through port 3306.

Similarly, in the PHP service, we first assign a name. Then, the image to load, the volume where we can place our page and then the ports to use. Finally, we must link the services and therefore the last line.

After that, use Docker Compose to make apply the file

:~# docker-compose up -d

Using docker compose
Using docker compose

As you can see, there is no error in the execution of the file and at the end, you will have the services running. Remember to open the ports in the firewall for everything to work.

On the contrary, if you want to stop the execution of the containers, run the following command:

:~# docker-compose down

So, that is it.

Conclusion

Using the best tools is vital for good server management results. Docker is an example of this. With this technology, it is possible to display images in a simple way and guaranteeing the compatibility of the programs.

Please share this post with your friends.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article