1. IntroductionDocker has an orchestration tool called docker-compose, which can orchestrate and manage multiple docker containers that make up a task. Similarly, in a Swarm cluster, you can use docker stack to orchestrate and manage a group of related services. Docker stack is also a yaml file, similar to a docker-compose.yml file, and the instructions are basically the same. But compared to compose, it does not support build, links and network_mode. Docker stack has a new command deploy. Note: stack does not support instructions 2. DeployDeploy is used to specify the configuration related to the deployment and runtime of swarm services, and it will only take effect when the swarm cluster is deployed using docker stack deploy. This option is ignored when using docker-compose up or docker-compose run. To use the deploy option, the version in the compose-file must be 3 or 3+. version: '3' services: redis: image: redis:alpine deploy: replicas: 6 update_config: parallelism: 2 delay: 10s restart_policy: condition: on-failure (1) ENDPOINT_MODE Specify the swarm service discovery mode
DNS round-robin (DNSRR) service discovery does not use a single virtual IP. Docker sets up DNS entries for services so that a DNS query for the service name returns a list of IP addresses, and clients connect directly to one of them. DNS round-robin is useful if you want to use your own load balancer, or if you have a mix of Windows and Linux applications. Note: version 3.3+ version: "3.3" services: wordpress: image: wordpress ports: -8080:80 networks: - overlay deploy: mode: replicated replicas: 2 endpoint_mode: vip mysql: image: mysql volumes: -db-data:/var/lib/mysql/data networks: - overlay deploy: mode: replicated replicas: 2 endpoint_mode: dnsrr volumes: db-data: networks: overlay: (2) LABELS Specifies the label of the service. These labels are set only on the service, not on any of the service's containers. version: "3" services: web: image: web deploy: labels: com.example.description: "This label will appear on the web service" To set labels on the container instead, use the labels key outside of deploy. version: "3" services: web: image: web labels: com.example.description: "This label will appear on all containers for the web service" (3) MODE Global (only one container per cluster node) or replicas (specify the number of containers). The default value is copied. version: '3' services: worker: image: dockersamples/examplevotingapp_worker deploy: mode: global (4) Placement Specifying constraints and preferences version: '3' services: db: image: postgres deploy: placement: constraints: - node.role == manager -engine.labels.operatingsystem==ubuntu 14.04 preferences: - spread: node.labels.zone (5) REPLICAS If the service is in replicated mode (the default), you can specify the number of containers that should run for the service. version: '3' services: worker: image: dockersamples/examplevotingapp_worker networks: -frontend - backend deploy: mode: replicated replicas: 6 (6) RESOURCES Resource Limit Configuration version: '3' services: redis: image: redis:alpine deploy: resources: limits: cpus: '0.50' memory: 50M reservations: cpus: '0.25' memory: 20M In the following example, the redis service is limited to use no more than 50MB of memory and 0.50 (50%) of the available processing time (CPU), and has 20MB of memory and 0.25 of the CPU time (always available). (7) RESTART_POLICY Configure whether and how to restart the container when it exits. Replaces the restart command.
version: "3" services: redis: image: redis:alpine deploy: restart_policy: condition: on-failure delay: 5s max_attempts: 3 window: 120s (8) UPDATE_CONFIG How to upgrade the configuration service
version: '3.4' services: vote: image: dockersamples/examplevotingapp_vote:before depends_on: - redis deploy: replicas: 2 update_config: parallelism: 2 delay: 10s order: stop-first (9) depends_on Represents dependencies between services version: '3' services: web: build: . depends_on: -db - redis redis: image: redis db: image: postgres (10) DNS Custom DNS servers. Can be a single value or a list. dns: 8.8.8.8 dns: - 8.8.8.8 - 9.9.9.9 (11) dns_search dns_search: example.com dns_search: - dc1.example.com - dc2.example.com (12) Environment Add environment variables. You can use an array or a dictionary. Any Boolean values; true/false, yes/no, need to be enclosed in quotes to ensure they are not converted to True or False by the YML parser. environment: RACK_ENV: development SHOW: 'true' SESSION_SECRET: environment: - RACK_ENV=development - SHOW=true -SESSION_SECRET (13) expose Opening ports in containers does not expose ports on the host; they are accessible only to the associated services. Only internal ports can be specified. expose: - "3000" - "8000" The above is the detailed content of the Docker Swarm service orchestration command. For more information about Docker Swarm service orchestration, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Summary of MySQL slow log related knowledge
>>: Experience of redesigning the homepage of TOM.COM
Table of contents 1. Realistic Background 2. Agre...
This article example shares the specific code for...
Preface Share two methods to monitor whether an e...
What is Nginx access restriction configuration Ng...
There are many servers that can host static websi...
Result: html <canvas id="starfield"&...
Table of contents Background Description Creating...
I have recently been following the CSS Animation ...
Preface This article mainly introduces the releva...
This article uses examples to describe how to use...
Share a Shell script under Linux to monitor the m...
Detailed example of removing duplicate data in My...
1. Download the mysql-5.7.17-winx64.zip installat...
Websites without https support will gradually be ...
Here is a Vue single sign-on demo for your refere...