Docker Swarmkit Learning Notes __docker

Source: Internet
Author: User
Tags redis docker swarm
Prerequisites:Docker engine version 1.12 or above network: TCP port 2377 for cluster Management communications TCP and UDP Port 7946 for communication AM Ong nodes TCP and UDP port 4789 for overlay network traffic

Create Swarm
--ADVERTISE-ADDR is optional and, if not specified, the IP of the Eth0 network card is selected by default.      Specified floating IP is not supported when specified. The commands for adding the work node and the manager node are listed in the output information. root@docker-1:~# Docker swarm init--advertise-addr 192.168.100.23 swarm node ( 0BW30FKEIREDI0FG1PXG710LD) is now a manager.
To add a worker to this swarm, run the following command:docker swarm join \--token SWMTKN-1-2HAYQ3EDOQV3LC5CHPW 23E76R8QP67CTX13DCEPGHDZU9JGNGY-0JI06X1FY8PFUNLXDY1P2WFM7 \ 192.168.100.23:2377
To add a manager to this swarm, run the following command:docker swarm join \--token SWMTKN-1-2HAYQ3EDOQV3LC5CHP W23E76R8QP67CTX13DCEPGHDZU9JGNGY-00O8M54KLDOV9BD24MI2DT8GU \ 192.168.100.23:2377 root@docker-1:~#
Once added, you can view node information by using the following command: root@docker-1:~# docker node ls ID HOSTNAME STATUS availability MANAGER ST ATUs 0bw30fkeiredi0fg1pxg710ld * docker-1 Ready Active Leader


Add node
Execute the automatically generated command in the Create swarm step to add the node. If you forget this command, you can query by the following command:
root@docker-1:~# Docker swarm Join-token worker to add a worker to this swarm, run the following command:docker Join \--token swmtkn-1-2hayq3edoqv3lc5chpw23e76r8qp67ctx13dcepghdzu9jgngy-0ji06x1fy8pfunlxdy1p2wfm7 \ 192.168.10 0.23:2,377 Modify the corresponding token information root@docker-1:~# docker swarm Join-token--rotate worker to add a worker to this swarm, run The following command:docker swarm join \--token swmtkn-1-42vudaylbg4ma3m5u22krw3ivd1rnbc7kryo3frerxo43jdjdm-2f S6GV0ME0T158B0YBT0E6FWF \ 192.168.100.23:2377

Add node: root@docker-2:~# docker swarm join \ >--token SWMTKN-1-2HAYQ3EDOQV3LC5CHPW23E76R8QP67CTX13DCEPGHDZU9JGNG Y-0JI06X1FY8PFUNLXDY1P2WFM7 \ > 192.168.100.23:2377 This node joined a swarm as a worker.
The lifting level of the node
Docker node promote node-3 node-2--upgrade worker to manager node Docker node demote node-3 node-2--Demote manager node to worker node



Deploying services on the Swarm
root@docker-1:~# Docker Service Create--replicas 1--name helloworld Alpine ping www.baidu.com 5ntljnr8mqu94hvdicnqbsxmb Docker Service create command--name the name of the specified service is HelloWorld--replicas specifies the number of running containers
To view services running: root@docker-1:~# Docker service ls ID NAME replicas IMAGE COMMAND 5ntljnr8mqu9 Helloword 1 /1 Alpine Ping www.baidu.com

Check the services on the cluster
root@docker-1:~# Docker Service Inspect--pretty helloword ID:5NTLJNR8MQU94HVDICNQBSXMB Name:helloword Mod e:replicated replicas:1 placement:updateconfig:parallelism:1 on Failure:pause Containerspec:ima Ge:alpine args:ping www.baidu.com Resources:
See which nodes are running the service root@docker-1:~# Docker service PS Helloword ID NAME IMAGE NODE desired State Current state ERROR 5PUJMICJJP25MM1W26M3YZ1VK Helloword.1 Alpine docker-1 Running Running m Inutes ago


Number of telescopic service
Docker Service Scale <SERVICE-ID>=<NUMBER-OF-TASKS>
Number of adjustments HelloWorld: root@docker-1:~# Docker Service scale helloword=5 Helloword to 5


remove service from Swarm
root@docker-1:~# Docker Service RM Helloword Helloword


Rolling Update Service
Create a Redis Services $ docker service create \--replicas 3 \--name redis \--update-delay 10s \ redis:3.0.6
0U6A4S31YBK7YW2WYVTIKMU50--update-delay: Set update time interval, seconds Ts, minutes Tm, or hours Th.      So 10m30s indicates a minute second delay. --update-parallelism: Set the number of containers per update--update-failure-action: Set the action after the update failed
--update-delay 、--update-parallelism 、--update-failure-action parameters can also be specified at update time. $ Docker Service Update--image redis:3.0.7 redis redis update steps: Stop the first container start a container if the update container returns running, wait for the time interval after the setting stops Next container If update fails, pause update


Drain Node
After node is set to drain, the container on the node is automatically stopped, and the new container is created on the other available nodes.
Docker node Update--availability drain Worker1
Worker1
$ Docker Node Update--availability active Worker1
Worker1

Service Related Commands
Basic Parameters Docker Service create--name helloworld \--env myvar=myvalue \--workdir/tmp \--user my_user \--replicas 3 \--publish 8080:80 \--network my-multi-host-network \--update-delay 10s \--update-parallelism 2 \--update -failure-action continue \ Alpine Ping docker.com
Volume related # type=volume, map the container directory to the volume store. Docker volume create a volume that can be used here. Docker service create \--mount type=volume,src=<volume-name>,dst=<container-path>,volume-driver=< Driver>,volume-opt=<key0>=<value0>,volume-opt=<key1>=<value1>--name MyService < Image>
# Type=bind, map the container directory directly in the host Docker service create \--mount type=bind,src=

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.