In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to solve the problem of using Docker Compose to manage containers. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
In Docker's design, a container runs only one application. However, most of the current application systems can not be composed of one application. Although the methods of connecting and exchanging data between containers have been mentioned earlier, a container group of complete application systems can be built by using these methods. However, there are a lot of commands to be executed and many relationships between applications and containers to be considered, and Docker Compose is designed to solve these complex operations.
Solve container management problems
Take the simplest example. If we are going to prepare a MySQL container and a Redis container for our backup container, then we need to start the MySQL container and Redis container before shipping the container each time we start. Don't forget to connect the container to the MySQL container and the Redis container when you create the container, so that you can connect them and exchange data.
This is not enough. if we have made various configurations for the container, we'd better save the commands for container creation and configuration so that we can directly configure the container next time.
If we want the system to switch like docker run and docker rm, it will be even more annoying, and we may need to write some scripts to avoid the "thread ball" that is wound to the command.
In fact, the core still lacks something to manage the combination of containers.
Docker Compose
Docker Compose: define and run software in multiple containers. In Docker Compose, according to a configuration file, all the applications and corresponding containers related to the application system are configured, and then started according to the commands provided by Docker Compose, the complex problems between multiple containers mentioned above can be solved. Docker Compose can be understood as solidifying the operation and configuration of multiple containers, similar to the effect of Dockerfile on mirroring.
Install Docker Compose# to 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# to view information after installation basic use of docker-compose versionDocker Compose
The core of Docker Compose is its configuration file, which is a file based on YAML format. Just as Dockerfile uses the name Dockerfile as the default file name for the image build definition, Docker Compose's configuration file has a default file name of docker-compose.yml.
A simple configuration
Version: '3'services: webapp: build:. / image/webapp ports:-"5000 image/webapp ports 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-pwvolumes: logvolume: {}
Docker Compose configuration artifacts can contain a lot of content, from the detailed control of each container to the definition of networks, data volumes, and so on.
Version is the version number of Docker Compose, and the latest one is 3. Services is the core of the configuration, defining the details of the container. Each services represents the configuration of an application cluster
Start and stop
Start
Docker-compose up, based on the configuration file, creates all configured containers, networks, data volumes, and so on, and starts them. Similar to the docker run command, and both are started in the foreground, and you need to add-d if you want to start as a daemon.
Docker-compose up-d
Docker-compose up will recognize the docker-compose.yml file of the directory where the current console is located by default. If you want to specify a directory, you can use the-f command, and specify the project name through the-t command.
Docker-compose-f. / compose/docker-compose.yml-p myapp up-d
Stop it
The docker-compose down command is used to stop all containers and delete them, while deleting configurations such as networks. That is, almost all the effects of this Docker Compose item are removed from the Docker.
Container command
These commands look similar to those in Docker Engine that operate on a single container. Let's take a look at a common one.
In Docker Engine, if we want to see the output of the main process in the container, we can make the output docker logs command. Since the naming of services running under Docker Compose is done by Docker Compose clients, it is obviously a bit annoying if we need to find the name of the container first if we directly make the shipping docker logs. We can directly use the command "docker-compose logs" to complete this task.
Docker-compose logs nginx
In the same way, there are similar commands in Docker Compose that can control one or some services separately.
With docker-compose create, docker-compose start and docker-compose stop, we can achieve the same effect as docker create, docker start and docker stop, except that the object of operation is changed from a container in Docker Engine to a service in Docker Compose.
Thank you for reading! This is the end of this article on "how to solve the problem of using Docker Compose to manage containers". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.