docker-compose, quickly orchestrate docker container clusters
Introduction to Docker Compose
Docker-Compose is an orchestration service of Docker. It is a tool for defining and running complex applications on Docker, allowing users to deploy distributed applications in clusters.
Through Docker-Compose, users can easily define a multi-container application with a configuration file, and then use one instruction to install all the dependencies of the application to complete the build. Docker-Compose solves the problem of how to manage orchestration between containers.
There are two important concepts in Compose:
- Service (service): An application container can actually include several container instances running the same image.
- Project: A complete business unit composed of a set of associated application containers, defined in the docker-compose.yml file.
A project can be associated with multiple services (containers). Compose manages the project, and uses subcommands to conveniently manage the life cycle of a group of containers in the project.
The Compose project is written in Python, and the implementation calls the API provided by the Docker service to manage the container. Therefore, as long as the operating platform supports the Docker API, you can use Compose on it for orchestration management
1.Docker-compose installation
curl -L https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m) > /tmp/docker-compose
sudo install /tmp/docker-compose /usr/local/bin/docker-compose
2. Install the completion tool (optional)
#安装
yum install bash-completion
#下载docker-compose脚本
curl -L https://raw.githubusercontent.com/docker/compose/$(docker-compose version --short)/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose
2. Detailed explanation of dcoker-compose file configuration
Placement name | description |
version | The version number of the docker-compose file |
services | Root node of all servers |
image | Specify the name of the image, if it does not exist locally, go to the warehouse to pull it |
ports | Specify port mapping |
expose | Port of the specified service |
volume | Mount the host directory |
network | Configure network intercommunication and isolation between services |
secrets | Configure password access between services |
healthcheck | health examination healthcheck: test:["CMD","curl","http://localhost:8080/check"] interval:5s timeout:5s |
depends_on | Dependent service |
environment | Specified environment variables |
evn_file | Specify the environment configuration file |
deploy | Specify deployment information |
build | Specify build information |
3.docker-compose example
reference
https://www.cnblogs.com/ityouknow/p/8648467.html