In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to use the Docker Compose method". In the daily operation, I believe that many people have doubts about how to use the Docker Compose method. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use the Docker Compose method". Next, please follow the editor to study!
Development environment component information nginx proxyjava1 serverjava2 serverjava3 servera Postgres database
It's not a big deal to run these services on one development server, but for small and medium-sized companies, a high-configuration development server is often occupied by multiple people. It is necessary to provide ports and other people's data modifications; of course, these problems are also minor problems, for example, my service just ran well, why can't I use it all of a sudden? The operation is as fierce as a tiger. Finally, it is found that a low-level dependency of the system has been unloaded, and these environmental problems seem simple, but they are actually very difficult to troubleshoot, because most of the wrong messages are not within your cognitive scope. Otherwise, how come there is always the idea that the operation and maintenance staff are metaphysics?
In addition, the production environment has deployed the Kubernetes platform, and it is necessary to provide images, so the development environment docker-compose.
Docker-compose runs a bunch of Docker containers
Docker Compose allows you to run a bunch of Docker containers that can communicate with each other in a file called docker-compose.yml. The orchestration file is as follows:
Version: "3.3"
Services:
Db:
Image: postgres
Volumes:
-. / tmp/db:/var/lib/postgresql/data
Environment:
POSTGRES_PASSWORD: password
Java_server1:
Image: java1
Volumes:
-.: / app/
Java_server2:
Image: java2
Volumes:
-.: / app/
Java_server3:
Image: java
Volumes:
-.: / app/
Web:
Image: nginx
Ports:
-"8777PUR 80"
The configuration is already included in the image, and sometimes I may need to modify the configuration temporarily. In that case, I will modify it by entering the container or mounting the internal configuration of the container to the host.
I invoke the part of the interaction between the services through the service name.
By using docker-compose, the network configuration is also very simple, for example, the configuration of my nginx section is as follows:
Location ~ / java1* {
Proxy_pass http://java_server1:8080;
}
Location java2 {
Proxy_pass http://java_server2:8081;
}
The company is too small to deploy a horbour, and the image doesn't have a place to store, so you can consider using data volumes to mount local files inside the image, while compose itself just provides a framework for orchestrating and starting, and enumerating all your services. Startup mode
I've been running docker-compose build to start my container, and then running docker-compose up to run everything.
Of course, sometimes only one of the images may be changed, or you can start it separately by using docker-compose create java_server2docker-compose start java_server2.
Depends_on can be set in the yaml file to better control when the container starts, but it doesn't matter to my service start order, so I didn't do it.
Test environment
For the functional test environment, the deployment method is no different from the development environment, but for testers, it becomes more enjoyable after connecting to docker-compose. Suppose we already have a set of automated test scripts, which can be tested in a completely independent environment before each launch, and the container can be destroyed directly after the test is completed. Do not consider the impact of data, environment, configuration, and so on. Especially for small and medium-sized companies, with few services, frequent releases, and access to the continuous deployment of CI/CD continuous integration, this approach is recommended.
Production environment
So far, I've tried to use this in a production environment with docker-compose. Although I can tolerate its slow startup speed, I still encounter some problems in the process of use, for example, the sequence of startup between multiple containers leads to bug, but you can use the https://github.com/vishnubob/wait-for-it script to control that one container must be started after another container is fully started. In addition, there is no scheduling, keep alive and other functions, change to find that it is better to use shell script to start. Of course, if you just deploy a small website and some simple stateless services, you can also consider using docker-compose. Kubernetes is still recommended for a large number of micro services (more than 50).
At this point, the study on "how to use the Docker Compose method" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.