In Docker's design, a container runs only one application. However, most of the current application systems cannot be composed of just one application. Although the methods of connecting and exchanging data between containers have been mentioned before, these methods can indeed be used to build a container group for a complete application system. However, many commands need to be executed and the relationships between many applications and containers need to be considered. Docker Compose is designed to solve these complex operations. Solving container management problemsTake the simplest example, if we want to prepare a MySQL container and a Redis container for our application container, then at each startup, we must first start the MySQL container and the Redis container, and then run the application container. Don't forget to connect the container network to the MySQL container and the Redis container when creating the application container so that the application can connect to them and exchange data. This is not enough. If we have configured the container in various ways, we'd better save the commands for creating and configuring the container so that we can use them directly next time. If we want this system to switch seamlessly like docker run and docker rm, it will be even more troublesome. We may need to write some scripts to avoid being trapped in the thread ball of commands. In fact, the core is still lacking something to manage container combinations. Docker ComposeDocker Compose: Define and run software in multiple containers. In Docker Compose, all applications and corresponding containers related to the application system are configured according to a configuration file, and then started according to the commands provided by Docker Compose, which can solve the complex problems between multiple containers mentioned above. Docker Compose can be understood as solidifying the operation mode and configuration of multiple containers, similar to the role of Dockerfile for images. Install Docker Compose#Download curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose #Set permissions chmod +x /usr/local/bin/docker-compose #View the installed information docker-compose version Basic use of Docker Compose The core of Docker Compose is its configuration file, which is a file based on the YAML format. Just as Dockerfile uses the name Dockerfile as the default file name for the image build definition, the Docker Compose configuration file also has a default file name version: '3' services: webapp: build: ./image/webapp ports: - "5000:5000" volumes: - ./code:/code -logvolume:/var/log links: -mysql - redis redis: image: redis:3.2 mysql: image:mysql:5.7 environment: -MYSQL_ROOT_PASSWORD=my-secret-pw volumes: logvolume: {} A Docker Compose configuration file can contain a lot of content, from detailed control of each container to the definition of networks, data volumes, etc. Start and Stop start up
stop Container Commands These commands look similar to the commands used to operate a single container in Docker Engine. Let's look at a few common ones.
Similarly, there are several similar commands in Docker Compose that can control one or more services individually. This is the end of this article about using Docker Compose to manage containers. For more information about Docker Compose managing containers, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of mysql filtering replication ideas
>>: Vue advanced usage tutorial dynamic components
Events can specify the execution of SQL code once...
I love coding, it makes me happy! Hello everyone,...
In addition to B-Tree indexes, MySQL also provide...
1. What is Docker Secret 1. Scenario display We k...
Preface Although some love in this world has a pr...
Modify the simplified file size and download the ...
This article shares the installation and configur...
cause I once set up WordPress on Vultr, but for w...
Table of contents 1. Introduction to MHA 1. What ...
The role of virtual DOM First of all, we need to ...
In desperation, I suddenly thought, how is the Sin...
Preface I don't know how long this friend has...
HTML structure <body> <div class="w...
Preface 1. This article uses MySQL 8.0 version Co...
1. The table tag is table, tr is row, td is cell, ...