docker swarm 多服务部署
********************
docker stack
命令格式:docker stack [options] command
Usage: docker stack [OPTIONS] COMMAND
Manage Docker stacks
Options:
--orchestrator string Orchestrator to use (swarm|kubernetes|all)
Commands:
deploy Deploy a new stack or update an existing stack
ls List stacks
ps List the tasks in the stack
rm Remove one or more stacks
services List the services in the stack
Run 'docker stack COMMAND --help' for more information on a command.
deploy:部署服务
ls:列出stack
ps:列出stack中的task
rm:删除statck
services:列出stack中的service
**************
docker stack deploy
命令格式:docker stack deploy [options] stack_name
Usage: docker stack deploy [OPTIONS] STACK
Deploy a new stack or update an existing stack
Aliases:
deploy, up
Options:
--bundle-file string Path to a Distributed Application Bundle file
-c, --compose-file strings Path to a Compose file, or "-" to read from stdin
--orchestrator string Orchestrator to use (swarm|kubernetes|all)
--prune Prune services that are no longer referenced
--resolve-image string Query the registry to resolve image digest and supported platforms ("always"|"changed"|"never") (default "always")
--with-registry-auth Send registry authentication details to Swarm agents
-c、--compose-file:docker-compose.yml文件
********************
示例
docker-compose.yml
version: "3.8"
services:
redis:
image: redis
ports:
- "6379:6379"
deploy:
replicas: 2
centos:
image: centos
deploy:
replicas: 1
placement:
constraints: [node.role == manager]
创建 stack:docker stack deploy -c "docker-compose.yml" my_stack
[root@centos docker-swarm]# docker stack deploy -c "docker-compose.yml" my_stack
Creating network my_stack_default
Creating service my_stack_redis
Creating service my_stack_centos
查看 stack:docker stack ls
[root@centos docker-swarm]# docker stack ls
NAME SERVICES ORCHESTRATOR
my_stack 2 Swarm
查看 stack service:docker stack services my_stack
[root@centos docker-swarm]# docker stack services my_stack
ID NAME MODE REPLICAS IMAGE PORTS
bzehlgwfyo1n my_stack_redis replicated 2/2 redis:latest *:6379->6379/tcp
hwf6ehuuoecv my_stack_centos replicated 0/1 centos:latest
查看 stack task:docker stack ps my_stack
[root@centos docker-swarm]# docker stack ps my_stack
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
x40zkn6s5zed my_stack_centos.1 centos:latest centos Ready Ready 2 seconds ago
vd75rp19jzsq \_ my_stack_centos.1 centos:latest centos Shutdown Complete 2 seconds ago
s11ans38uk3q \_ my_stack_centos.1 centos:latest centos Shutdown Complete 8 seconds ago
u4mxzswyalgk \_ my_stack_centos.1 centos:latest centos Shutdown Complete 14 seconds ago
e3wiganrxpq8 \_ my_stack_centos.1 centos:latest centos Shutdown Complete 19 seconds ago
hwbveakpi3wq my_stack_redis.1 redis:latest centos Running Running 12 minutes ago
s196ohqsflra my_stack_redis.2 redis:latest centos Running Running 12 minutes ago