How To Install Docker Compose on Centos 7

How To Install Docker Compose on Centos 7 Хостинг

How To Install Docker Compose on Centos 7?

First, you can verify your Docker installation by checking its version:

Output
Docker version 24.0.1, build 6802122

Step 2 – Download Docker Compose Binary Package

At this point, you need to visit the GitHub Docker Compose release page and use the curl command to get the latest binary package under /usr/local/bin/ directory:

sudo curl -L «https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-$(uname -s)-$(uname -m)» -o /usr/local/bin/docker-compose

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

Step 3 – Verify Docker Compose Installation on Centos 7

Next, you can check your Docker compose installation by checking its version:

sudo docker compose version

Output
Docker Compose version v2.18.1

Step 4 – How To Use Docker Compose?

To see that Docker Compose is working correctly, we want to test it with a sample Docker container on Centos 7.

First, create a new directory for setting up the docker-compose file with the command below:

Switch to your directory with the command below:

Then, you need to create a docker-compose.yml file. This is a configuration file where you can define your container’s information.

sudo vi docker-compose.yml

version: ‘2’
services:
hello-world:
image:
hello-world:latest

When you are done, save and close the file.

Docker Compose Up Command

Next, launch the container within the ‘compose-test’ directory:

sudo docker compose up

From the output, you should see that your Docker compose is working correctly on Centos 7.

Step 5 – Uninstall or Remove Docker Compose

sudo rm /usr/local/bin/docker-compose

Uninstall the Docker Compose software by running this command:

sudo yum remove docker-compose

sudo yum autoremove

Conclusion

Hope you enjoy it. You may be interested in these articles on the orcacore website:

Install ionCube PHP Loader on Rocky Linux 9

How To Set up Grafana on Rocky Linux 9

How To Install OpenJDK 17 on Debian 11

Dockerisation has redefined the deployment and automation process in the software industry. Since its inception, the Docker team has continuously strived to make automated deployment seamless. Containerization technology does not just enable rapid application development and efficiency, but also saves time and strenuous efforts. Unbeatable functionalities such as orchestrating, defining, and running multi-container applications together make Docker a favorite pick for developers.

Docker Containers and Images

As you dive in to further understand Docker, it is essential to brush up with the basics. Understanding how Docker works can be tricky if you have no experience working with it. In this section, we are going to define a few concepts that are essential for beginners. If you think you are familiar with these concepts, feel free to skip and move forward with the next section. You can also take a look at our comprehensive guide that explains the fundamental Docker concepts.

Docker images are a collection of read-only files. Once you create Docker images, you cannot modify them, though it allows deletion. We use a Docker image to create one or more Docker containers as per our needs. To check the number of images running in your system, use the command:

When you pull images from a remote registry like Docker Hub, you are downloading files and folders. To pull an image, use the command:

Docker images are the blueprint of Docker containers. Technically, a Docker container is an instance of a Docker image. Imagine, if a Docker image is like a parent, then a Docker container is the child. Unlike Docker images which you can create once, you can create multiple containers using a single image. To check the list of images running in your system, use the command:

Docker images and containers work hand-in-hand to unleash the potential of Docker. A single container is built using the Docker image through the run command. When you create a Docker container, a new layer known as Container Layer is created. The newly created layer contains the application and its dependencies. Every container you create has a different read/write Container Layer, and any changes made in the Docker container are automatically reflected upon the Container Layer. Remember, if you choose to delete a container, you will also lose the Container Layer.

Say Hello to Docker Compose

Docker Compose is a container management tool that allows you to configure and orchestrate all your Docker containers into a single YAML file. Starting, halting, and creating intra-container linkages and volumes are all made easier with this tool.

In this guide, we will walk you through the steps of installing the current version of Docker Compose for managing multi-container applications on CentOS 7. We will also go over some basic commands you need to successfully use the software.

Читайте также:  Лучшие веб-сайты, на которых можно скачать модули FreePBX

Using Docker Compose is extremely easy, even for newbies. Let us see the three-step process involved in Docker Compose:

1. Build: At first, build images in the Dockerfile as per your project needs, or perhaps pull from the registry.

2. Define: Next, you need to define all the component services in the compose.yml file.

3. Run: After defining the components, it’s time to run using the docker-compose command.

Prerequisites

Before we move forward with installing Docker Compose on your CentOS server, make sure you have:

Installing Docker Compose

To make the binary run, set the permissions below:

Next, look up your version to check if the installation was successful:

The below code will print the installed version:


How To Install Docker Compose on Centos 7

You may then run a “Hello World” example using the Docker Compose that you have installed.

Using Docker Compose to Run a Container

There is a “Hello World” image in Docker Hub, the public Docker registry, which may be used for demonstration and testing. It shows how to run a container using Docker Compose with the very minimal configuration. First, you need to create a directory for our YAML file:

Next, move to this directory:

Then, using your preferred text editor, generate the YAML file. In this tutorial, we will use Vi:

Press i to get to insert mode, then type this into the file:

In the container name, the first line will be incorporated. The second line instructs the program which image it should use to create the container. docker-composeup will look for a local image by the name hello-world to check if it is available when you type the command. To exit insert mode, press ESC. Then, enter 😡 and press ENTER to save and quit the file. The docker images command can be used to manually check for images on your machine:

Only the column headings appear when there are no local images at all:


How To Install Docker Compose on Centos 7

To create the container, run this command while still in the /hello-world directory:

When you run the command for the first time and there isn’t a local image named hello-world, it will be downloaded from the Docker Hub repository:


How To Install Docker Compose on Centos 7

To ensure that the installation works, Docker Compose pulls in the image, builds a container, attaches it, and executes the hello program:


How To Install Docker Compose on Centos 7

After that, a printout of a description of what was done is displayed:


How To Install Docker Compose on Centos 7

When hello completes its duty, the container will be shut down and the command will no longer be running in the container. Column headings will be displayed when looking at active processes. However, the hello-world container will not be listed because it is not currently operating:


How To Install Docker Compose on Centos 7

To see all containers, not just the current ones, use the -a flag:


How To Install Docker Compose on Centos 7

Now that you’ve tried running a container, you may go on to learn some of the fundamental Docker Compose commands.

Docker Compose Commands

To get you started with Docker Compose, this section will go over the basic commands provided by the docker-compose tool. docker-compose is a command that works on a directory-by-directory basis. By generating one directory for each container and one docker-compose.yml file per directory, you can run many groups of Docker containers on the same computer.

So far, you have been running Docker Compose on your own. You can shut it off by pressing Ctrl-C. This enables the terminal window to display debug messages. However, it is advisable to run docker-compose as a service when operating in production. The -d option can be used as a simple way to accomplish this:

The State of a container will be reported as Exited if it is halted, as seen in the example below:

A container that is currently running will display:

You can terminate all running Docker containers in the same directory as the docker-compose.yml file that you used to start the Docker group:

Note: If you need to shut things down more forcibly, docker-compose kill is also available.

In some instances, Docker containers may be able to save their old data inside. Use the rm command to remove all containers from your container group if you want to begin from scratch:

Running any of these commands from another directory than the one where the Docker container and .yml file is placed will result in an error message:

It is possible to run a command prompt in a container and access the container’s filesystem using docker exec, which is a command-line tool. As an example, run “Hello World” and see how long it takes for the docker exec command to complete. For the sake of this tutorial, the Docker Hub image of Nginx can be utilized. Create a new directory named nginx and move into it:

You should now have a docker-compose.yml file, which you can open in a text editor:


How To Install Docker Compose on Centos 7

How To Install Docker Compose on Centos 7

If you wanted to alter the filesystem inside this container, using docker exec, you’d use the container’s unique ID (in this case, f139d0d78ca7) to build a shell within the container:


How To Install Docker Compose on Centos 7

An interactive terminal can be opened by using the -t option, whereas /bin/bash provides the container with a bash shell. This is the bash prompt you’ll see for the container after that:

Within your container, you’ll find a command prompt. Restarting the container will overwrite any changes you’ve made unless you’re working in a directory that has been saved as part of a data volume. If you’re accustomed to working with Linux command-line facilities, you should know that most Docker images are produced using the most basic Linux installs.

Читайте также:  Expansion Slots And Ports; Mode Button; Led Indicators

We walked you through the steps of installing the current version of Docker Compose for managing multi-container applications on CentOS 7. The ability of Docker Compose to simultaneously put up and shut down a large number of containers is impressive. Going from templates to applications takes minutes. Thus, if your work involves running multiple containers at once, sticking with Docker Compose is a great option. Yet, it is not a one-fit-all solution. You can also find some better options, depending on your particular needs, for example, Kubernetes.

To further explore the power of Docker Compose, you can refer to these tutorials from our blog:

При установке Docker и Docker Compose в Centos 8 есть небольшие различия, по сравнению с Centos 7

Установка Docker

Устанавливаем необходимые пакеты

$ sudo dnf -y install -y yum-utils device-mapper-persistent-data lvm2

Добавляем репозиторий Docker CE

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

Selectel — ведущий провайдер облачной инфраструктуры и услуг дата-центров

Компания занимает лидирующие позиции на рынке на рынке выделенных серверов и приватных облаков, и входит в топ-3 крупнейших операторов дата-центров в России.

$ sudo dnf -y install docker-ce —nobest

Add our user, under which we configure the OS, to the Docker group

Apply changes to groups

$ newgrp docker

Add the service to startup and start it

$ sudo systemctl enable —now docker

$ docker -v
Docker version 19.03.12, build 48a66213fe

Installing Docker Compose

Download docker-compose to /usr/local/bin/ directory

$ sudo curl -L «https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)» -o /usr/local/bin/docker-compose

Making the file executable and creating a symlink

$ sudo chmod +x /usr/local/bin/docker-compose
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

$ docker-compose -v
docker-compose version 1.26.2, build eefe0d31

Setting up firewall

NAT must be enabled to run docker compose with external web server access on Centos 8

$ sudo firewall-cmd —zone=public —add-masquerade —permanent
$ sudo firewall-cmd —reload

The blog has a new hosting from Selectel.
Did you find interesting or useful information in the blog? Would you like to see even more useful articles on it? Support the author with a ruble.

If you post materials from this site on your blog, social. networks, etc., please kindly publish a link back to the original.

Docker Compose is a package manager that allows you to describe the necessary structure in one file (config).

$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

Adding the docker-ce repository

$ sudo yum-config-manager —add-repo https://download.docker.com/linux/centos/docker-ce.repo

$ sudo yum install -y docker-ce

Adding the EPEL repository

$ sudo yum install -y epel-release

$ sudo yum install -y python-pip python-devel gcc
$ sudo yum install -y python3-pip

Install Docker Compose

$ sudo pip3 install docker-compose

Making a symlink to the docker-compose file

Update pip utility

$ sudo pip install —upgrade pip

$ sudo yum upgrade python*

$ sudo docker-compose version

Installing Docker Compose Method #2

$ sudo curl -L «https://github.com/docker/compose/releases/download/1.25.3/docker-compose-$(uname -s)-$(uname -m)» -o /usr/local/bin/docker-compose

Introduction

Docker is a platform that makes running and managing application processes in containers easier. It provides a way to separate your applications from your infrastructure. Containers are very similar to virtual machines, but they are more portable, efficient, and easy to use. There are various ways to install Docker on Linux distributions. The most popular and easy way to install Docker on the existing operating system is by using yum commands.

This tutorial will demonstrate how you can set up and use Docker on CentOS 7 in a few simple steps.

Setting up Docker on CentOS 7 Instance

The official CentOS 7 repository may not have the latest installation package for Docker. In this section, you’ll be installing the latest version of Docker from the official Docker repository. First, you need to update the package database using:

After the update step is complete, run the below command to download and install the latest version of Docker:

Docker is now installed, hence you can start the Docker daemon by running the command below:

Finally to make sure Docker starts up as you reboot your machine use the command:

The Docker installation provides you with Docker service as well as the client utility (Docker command-line client). In the next sections of the tutorial, you’ll be able to get more hands-on using the Docker commands.

You can also take a look at our in-depth tutorial on how to install & operate Docker on Ubuntu in the public cloud.

Using Docker Commands Without Sudo Prefix

Now that you have Docker installed and running, let’s look at some commands to get familiar with the Docker command-line utility. Docker commands usually take the form of:

To find all the available subcommands you should use:

As of Docker 20.10.3, the complete list of available subcommands includes:

You can use –help flag with a specific command to get more information about it:

To get detailed information about the system, use:

Working with Docker Images

Docker images can be called the blueprint for Docker containers. These images are usually pulled from the Docker Hub, which is a registry managed by the Docker project. Anyone can create and push their images on the Docker Hub. As a result, you can easily find a wide variety of applications and os distributions in the registry. Let’s try out a simple program that will confirm access to the Docker Hub:

Читайте также:  Освоение исправлений ошибок хоста: эффективные стратегии для владельцев веб-сайтов

You should get an output as below, which shows that Docker is working:

You can find various Docker images on the Docker Hub by using the search command. For example, see the below command to search for a CentOS image:

The search query will show up a list of all the images which matched with the substring. In your case the output should be like:

In the search results, there are different columns describing information about the image. The OK in the OFFICIAL column determines that the image was created and supported by the company behind the application. Once you have finalized the image, you can download it to your local machine using the Docker pull command:

After downloading the image, you can run the container using the Docker run command. If you directly try to run an image without prior downloading, Docker will download the image and run the container afterward:

You can list the images that are downloaded to your local machine, using the below command:

You should get a similar output:

Later in this tutorial, you’ll be able to modify the images to run the containers. These new images can be added or pushed in the Docker Hub and other registries that host the Docker images.

Running a Container Interactively

There are different types of containers. The hello-world container you ran in Step4 is a type of container which runs and exits after printing a message. Another type of container is the interactive one. You can use interactive containers in a similar fashion as a virtual machine.

Let’s create a container from the latest CentOS image. Using -i and -t flags in the Docker run command will give interactive access to the CentOS container:

The command prompt will change and it should look like the output below:

Now any command you execute will run inside the container. That is similar to running a command in a virtual machine. Let’s try installing MySQL server in the CentOS container. You can do this using:

Committing Changes in a Container to a Docker Image

After starting the container, you can do all the operations which are doable in a similar virtual machine, like creating/modifying the files or setting up an app. Please note that these changes will only stay for that container, and after you destroy the container the changes you made will be lost.

In this part of the tutorial, you’ll learn how to create a new Docker image from a container with the changes you have made. After Step5 you have a CentOS container running with MySQL server installed. This container is now different than the plain CentOS image. You can save this state of container for further use. First, you need to exit the container using:

Commit the changes you have made in the container to a new Docker image using the below command:

Now that the image is committed, the Docker images command should list the new image as well as the old ones:

The output of the command should be similar as below:

As seen in the example, a new image centos-mysql is created using the CentOS image from the Docker Hub. The difference in size determines that some changes were made. In this example, it was the addition of the MySQL server in the container. Next time if you need a container with a MySQL server, you can just run the new image, and voila! You have a CentOS container with a pre-installed MySQL server running.

Managing Docker Containers

Now that you are familiar with Docker, after using it for some time you already have some running and some inactive containers. To get the list of active containers you should use:

You should see a similar output:

In order to list both the active and inactive containers, you should use the -a flag with the command:

To find the last container you created, you can provide -l flag:

To stop a running/active container run a simple command:

You can find the container-id in the output of Docker ps command.

Publishing the Images to a Repository

In the next part of the tutorial, you’ll learn how to push the images to Docker Hub. First, sign up on Docker Hub. You’ll need to log into Docker Hub to push your image using the command below:

Once you provide the right password, and authentication is successful, you can push your image. To push the image use the below command:

The output for the command will be similar to this:

Once you have pushed the image, it should show up on your account’s dashboard, as shown in the image below:

In case of failure in a similar way, chances are that you have not logged in:

You can log in, and repeat the push attempt.

There are a number of ways in which you can make use of Docker. This tutorial should provide you with enough information to get you started. And since Docker is a really trending project, you can find many details about the usage as well as different use cases from the project’s blog page.

Оцените статью
Хостинги