Docker Company: Simplify the layout of containerization applications
In modern back-end development, an application usually consists of multiple services (e.g. Web servers, databases, caches, etc.). Docker Compose It's an official Docker tool that allows you to define and run multi-container applications through a YamL file.
1. Specific issues addressed: getting rid of the lengthy Docker command
If you start the container manually, you might need to run a long line.
docker run
Command, complex.
-p
(ports)
-v
(mounted)
-e
(Variability) parameters.
-
One click to start:
Just one.
docker-compose up, you can start all associated services in sequence. - Environmental coherence: The configuration file follows the code to ensure that the packaging configuration of the development, testing and production environment is fully consistent.
-
Service found:
Compoce automatically creates a network for services, which can be used by name between services (e.g.
db) Access to each other without the need to maintain the IP address manually.
2. Analysis of the concept of core configuration
- Services: A service is a container. You can specify the mirrors, the building paths, the environment variables, etc. that you use.
- Volumes (data volume): Mounts the host's directory or file in a container. This is the hot update of the database for its sustainability and development (Hot) The key to the Redaad.
- Networks: Defines the separation of communication between containers. By default, the service under the same Compoce file is in the same network.
- Envirronment (Environmental Variables): The mode of recommending the transmission of sensitive information (e.g. database passwords) or configuration items (e.g. API addresses).
3. Production environment recommendations
When used in the production environment, it is recommended to assign specific version labels for mirrors (e.g.
mysql:8.0
Not
latest
The government has been monitoring the situation and ensuring stability. At the same time, use it.
restart: always
Ensure that the container is automatically restored after the server is restarted.