Home / How To / Install and use Docker Compose on CentOS 8

Install and use Docker Compose on CentOS 8



Docker Compose is a tool that can be used to define and run multiple containers as a single service. With Docker Compose you can link multiple containers and distribute an application from a single command. It is mainly used in development, testing and staging environments. Docker Compose uses a YAML file to define a complex stack in a file and run it with a single command.

In this tutorial we will show you how to install and use Docker Compose in CentOS 8.

Requirements [19659004] A server running CentOS 8.
  • A root password is configured on the server.
  • Installing Docker

    Before you start, make sure Docker is installed on your server. If it is not installed, you must add the Docker-CE archive to your system. You can add it with the following command:

      dnf config-manager --add-repo = https: //download.docker.com/linux/centos/docker-ce.repo 

    Once the repository has been added, install the latest version of docker with the following command:

      dnf install docker-ce --nobest -y 
      systemctl start docker 
    systemctl enable docker

    You can verify the docker version with the following command: [1

    9659007] docker – version

    You should see the following output:

      Docker version 19.03.5, build 633a0ea
    

    Installing Docker Compose

    By default, Docker Compose is not available in the CentOS 8 standard repository. So you have to download it from the Git layer.

    First install the curl command with the following command:

      dnf install curl -y 

    Then download the latest version of Docker Compose from the Git repository using the curl shown below:

      curl -L https : //github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` -o / usr / local / bin / docker-compose 

    When the download is complete, make the downloaded binary executable with the following command:

      chmod + x / usr / local / bin / docker-compose 

    Next, you can verify the Compose version with the following command:

      docker- compose --version 

    You should see the following output:

      docker-compose version 1.25.0, build 0a186604
    

    You can see all available options with docker-compose with the following command:

      docker-compose - help 

    You should see the following page:

    <img src = "https: //www.howtoforge. com / images / install_and_use_docker_compose_on_centos_8 / page1.png "alt =" Docker Compose Commandline Options [19659032] Distribute Drupal with Docker Compose

    This section shows how to install Drupal with Docker Compose.

    First, create a directory for your drupal with the following command:

      mkdir drupal 

    Next, create a drupal.yaml file in the drupal directory:

      nano drupal / docker-compose.yaml 

    Add the following content:

      version: & # 39; 3.3 & # 39;
    
    services:
    Drupal:
    image: drupal: latest
    ports:
    - 80:80
    volumes:
    - drupal_modules: / var / www / html / modules
    - drupal_profiles: / var / www / html / profiles
    - drupal_themes: / var / www / html / themes
    - drupal_sites: / var / www / html / sites
    restart: always
    
    postgres:
    image: postgres: 10
    environment:
    POSTGRES_PASSWORD: your_postgres_password
    volumes:
    - db_data: / var / lib / postgresql / data
    restart: always
    
    volumes:
    drupal_modules:
    drupal_profiles:
    drupal_themes:
    drupal_sites:
    db_data:
    

    Save and close the file when you are done. Then switch the directory to drupal and start your Docker container with the following command:

      cd drupal 
    docker-compose up -d

    The above command downloads and runs the drupal and postgresql containers.

    You can check your drive containers with the following command:

      docker-compose ps 

    You should see the following output:

      Name Command State Ports
    -------------------------------------------------- -----------------------------
    drupal_drupal_1 docker-php-entrypoint apac ... Up 0.0.0.0:80->80/tcp
    drupal_postgres_1 docker-entrypoint.sh postgres Up 5432 / tcp
    

    You can now visit the URL http: // your-server-ip to access the Drupal Web Installation Guide shown below:

     Select language

    Working with Docker Compose

    In this section , we show you how to use the docker-compose command.

    To stop the Docker Compose services, run the following command in the drupal directory:

      docker-compose stop 

    You should see the following output: [19659015] Stop drupal_drupal_1 … done
    Stopping drupal_postgres_1 … ready

    To start Docker Compose services run the following command in the drupal directory:

      docker-compose start 

    To view the container log run the following command:

      docker-compose logs 

    To view the logs for a specific container run the following command:

      docker-compose logs drupal 

    You can view your configuration file with the following command:

      docker-compose config 

    To pause and pause the containers run the following command: [19659007] docker-compose pause

    Output:

      Pause drupal_postgres_1 ... done
    Pausing drupal_drupal_1 ... done
    
      docker-compose unpause 

    Output:

      Unpausing drupal_drupal_1 ... done
    Canceling drupal_postgres_1 ... done
    

    To remove all containers run the following command:

      docker-compose down 

    You should see the following output:

      Stop drupal_drupal_1 ... done
    Stopping drupal_postgres_1 ... ready
    Removing drupal_drupal_1 ... done
    Removing drupal_postgres_1 ... done
    Removes the network drupal_default
    

    You can also delete the data volumes with the following command:

      docker-compose down - volumes 

    You should see the following output:

      Remove the network drupal_default
    WARNING: The network drupal_default was not found.
    Removes the volume drupal_drupal_modules
    Removes the volume drupal_drupal_profiles
    Removes the volume drupal_drupal_themes
    Removes the volume drupal_drupal_sites
    Removes the volume drupal_db_data
    

    Conclusion

    In the above tutorial, we learned how to install and use Docker Compose in CentOS 8. I hope you have enough knowledge on how to use the Docker Compose command to manage the Docker containers.


    Source link