write a docker-compose.yml
version: "3"
services:
web:
# replace username/repo:tag with your name and image details
image: username/repo:tag
deploy:
replicas: 5 //实例数量
resources:
limits:
cpus: "0.1" //分配cpu百分比
memory: 50M //分配内存
restart_policy:
condition: on-failure //挂掉自动重启
ports:
- "4000:80" //端口映射
networks:
- webnet //默认网络设置
networks:
webnet:
相关命令:
docker swarm init //实例化swarm
docker stack ls # List stacks or apps
docker stack deploy -c <composefile> <appname> # Run the specified Compose file
docker service ls # List running services associated with an app
docker service ps <service> # List tasks associated with an app
docker inspect <task or container> # Inspect task or container
docker container ls -q # List container IDs
docker stack rm <appname> # Tear down an application
docker swarm leave --force # Take down a single node swarm from the manager