Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is docker service management like?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you what docker service management is like. It is concise and easy to understand. It will definitely make your eyes shine. I hope you can gain something from the detailed introduction of this article.

How to manage services in a convenient way.

Docker-compose, which we mentioned earlier, is suitable for local development and can be deployed natively, providing great convenience. Swarm is a cluster. Can you implement the defined application through docker-compose? The answer is yes, but not recommended. Just use the docker command line. We can still use docker-compose.yml file to define an application, but we usually do not use docker-compose to deploy, but directly use docker command, and our deployment can only be used for swarm cluster.

deployversion "3.3"services: wordpress: image: wordpress ports: - 8080:80 networks: - overlay deploy: mode: replicated replicas: 2 endpoint_mode: vip placement: constraints: - node.role == manager - engine.labels.operatingsystem == ubuntu 16.04 preferences: - spread: node.labels.zone resources: limites: cpus: '0.50' memory: 50M

Here's an example:

endpoint_mode has two values

The first type is vip, which is the virtual ip introduced earlier. VIP is exposed when user services access each other. When accessing through virtual IP, the bottom layer Load Balancer virtual IP into IP address of a specific service through LVS.

The second is dnsrr, DNS round-robin. This way does not use virtual ip, but directly use the ip address of the service, we know that there are many ip addresses of the service, especially after we have done horizontal expansion, each service has its own ip address, if we use dnsrr, we do not use IP address, but use dns.

The default is vip.

Mode has two different values.

The first type is global, meaning that there is only one service in the global cluster. No horizontal expansion.

The second is replicated, the default value. It can be extended horizontally.

placement

Used to set some restrictions on service.

For example, the WordPress service above must be deployed to the Manager node.

replicas

If the mode of this service is set to replicated, it can be defined at initialization time, and several replicas are required.

resources

limit indicates the maximum CPU and memory usage.

restart_policy

If the service stops for some reason, do you need to restart it and some conditions for restarting it?

update_config

To do some configuration, for example, when doing some updates to the service, some principles to follow. For example, setting parallelism:2 means that at most 2 replicas can be updated at the same time, and delay is the delay time after each update.

experimental

We still use WordPress for this experiment environment.

Our docker-compose.yml file reads:

version: '3'services: web: image: wordpress ports: - 8080:80 environment: WORDPRESS_DB_HOST: mysql WORDPRESS_DB_PASSWORD: 123456 networks: - my-network depends_on: - mysql deploy: mode: replicated replicas: 3 restart_policy: condition: on-failure delay: 5s max_attempts: 3 update_config: parallelism: 1 delay: 10s mysql: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: 123456 MYSQL_DATABASE: wordpress volumes: - mysql-data:/var/lib/mysql networks: - my-network deploy: mode: global placement: constraints: - node.role == managervolumes: mysql-data:networks: my-network: driver: overlay

This yml file is suitable for local deployment using the docker-compose tool. If you want to deploy to a swarm cluster, docker-compose is not appropriate. Reason 1: networks. When we deploy in a local docker-compose, our network is a bridge, but when we deploy in a swarm, our service will be distributed to different machines. Therefore, networks cannot use a bridge and needs to be changed to an overlay.

In the above configuration, mysql service is set to: mode:global to indicate that this mysql service is not allowed to do replicas. And limit mysql deployment to manager nodes only.

wordpress: run in replicas mode and initialize replicas=3

The command we want to deploy docker-compose.yml to swarm cluster is docker stack

The docker-compose above defines a stack, which is called WordPress. We define two services in the WordPress stack, one is WordPress and the other is MySQL.

Execute orders:

iie4bu@swarm-manager:~/ddy/docker-compose-swarm$ vim docker-compose.ymliie4bu@swarm-manager:~/ddy/docker-compose-swarm$ lsdocker-compose.ymliie4bu@swarm-manager:~/ddy/docker-compose-swarm$ docker stack deploy wordpress --compose-file=docker-compose.ymlCreating network wordpress_my-networkCreating service wordpress_webCreating service wordpress_mysql

Check out the current stack:

iie4bu@swarm-manager:~/ddy/docker-compose-swarm$ docker stack lsNAME SERVICESwordpress 2

You can see a WordPress stack.

Check out WordPress stack details:

iie4bu@swarm-manager:~/ddy/docker-compose-swarm$ docker stack ps wordpressID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTSqzpzs6kj1ec5 wordpress_mysql.yd42nx646854nrzyqohwmpgwi mysql:5.7 swarm-manager Running Running about a minute ago se9rn27p694f wordpress_web.1 wordpress:latest swarm-worker2 Running Running 2 minutes ago lz10x51q2on8 wordpress_web.2 wordpress:latest swarm-worker1 Shutdown Failed about a minute ago "starting container failed: fa…" z8tsp0b08uzs \_ wordpress_web.2 wordpress:latest swarm-worker1 Shutdown Failed about a minute ago "starting container failed: fa…" f1dh6i8xqlrf \_ wordpress_web.2 wordpress:latest swarm-worker1 Shutdown Failed about a minute ago "starting container failed: fa…" n3la11ttg30v \_ wordpress_web.2 wordpress:latest swarm-worker1 Shutdown Failed 2 minutes ago "starting container failed: fa…" 8n4gcxt3b1kv wordpress_web.3 wordpress:latest swarm-manager Running Running 2 minutes ago

A web service was found not to start successfully. The reason is unknown.

It can be accessed through a browser.

The above is how docker service management is. Have you learned knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report