1. Docker swarm init
$ docker swarm init --advertise-addr $(host -i)
docker swarm init --advertise-addr $(hostname -i)
Swarm initialized: current node (s19krjqmzoz0zozspjszjojdk) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-589slthktmh85s376jqypz4qtt8qyj7nbpjj6i840sgm0nfo2m-87sdp1mneat2kxiwo6tblag3c 192.168.0.13:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
$ docker swarm init --advertise-addr $(host -i) docker swarm init --advertise-addr $(hostname -i) Swarm initialized: current node (s19krjqmzoz0zozspjszjojdk) is now a manager. To add a worker to this swarm, run the following command: docker swarm join --token SWMTKN-1-589slthktmh85s376jqypz4qtt8qyj7nbpjj6i840sgm0nfo2m-87sdp1mneat2kxiwo6tblag3c 192.168.0.13:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
2. Docker node ls
$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
s19krjqmzoz0zozspjszjojdk * node1 Ready Active Leader 19.03.11
$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
s19krjqmzoz0zozspjszjojdk * node1 Ready Active Leader 19.03.11
3. Docker stack deploy
$ docker stack deploy --help
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
$ docker stack deploy --help
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
3. Docker stack deploy
$ docker stack deploy --help
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
$ docker stack deploy --help
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
$ docker stack deploy --compose-file=docker-stack.yml voting_stack
Creating network voting_stack_backend
Creating network voting_stack_frontend
Creating network voting_stack_default
Creating service voting_stack_result
Creating service voting_stack_worker
Creating service voting_stack_visualizer
Creating service voting_stack_redis
Creating service voting_stack_db
Creating service voting_stack_vote
$ docker stack deploy --compose-file=docker-stack.yml voting_stack
Creating network voting_stack_backend
Creating network voting_stack_frontend
Creating network voting_stack_default
Creating service voting_stack_result
Creating service voting_stack_worker
Creating service voting_stack_visualizer
Creating service voting_stack_redis
Creating service voting_stack_db
Creating service voting_stack_vote
$ cat docker-stack.yml
version: "3"
# create required networks and volummes.
# services, networks, volumes, all are duplications.
networks:
frontend:
backend:
volumes:
db-data:
services:
redis:
image: redis:alpine
networks:
- frontend
deploy:
replicas: 1
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure
db:
image: postgres:9.4
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "postgres"
volumes:
- db-data:/var/lib/postgresql/data
networks:
- backend
deploy:
placement:
constraints: [node.role == manager]
vote:
image: dockersamples/examplevotingapp_vote:before
ports:
- 5000:80
networks:
- frontend
depends_on:
- redis
deploy:
replicas: 2
update_config:
parallelism: 2
restart_policy:
condition: on-failure
result:
image: dockersamples/examplevotingapp_result:before
ports:
- 5001:80
networks:
- backend
depends_on:
- db
deploy:
replicas: 1
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure
worker:
image: dockersamples/examplevotingapp_worker
networks:
- frontend
- backend
depends_on:
- db
- redis
deploy:
mode: replicated
replicas: 1
labels: [APP=VOTING]
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 3
window: 120s
placement:
constraints: [node.role == manager]
visualizer:
image: dockersamples/visualizer:stable
ports:
- "8080:8080"
stop_grace_period: 1m30s
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
deploy:
placement:
constraints: [node.role == manager]
$ cat docker-stack.yml version: "3" # create required networks and volummes. # services, networks, volumes, all are duplications. networks: frontend: backend: volumes: db-data: services: redis: image: redis:alpine networks: - frontend deploy: replicas: 1 update_config: parallelism: 2 delay: 10s restart_policy: condition: on-failure db: image: postgres:9.4 environment: POSTGRES_USER: "postgres" POSTGRES_PASSWORD: "postgres" volumes: - db-data:/var/lib/postgresql/data networks: - backend deploy: placement: constraints: [node.role == manager] vote: image: dockersamples/examplevotingapp_vote:before ports: - 5000:80 networks: - frontend depends_on: - redis deploy: replicas: 2 update_config: parallelism: 2 restart_policy: condition: on-failure result: image: dockersamples/examplevotingapp_result:before ports: - 5001:80 networks: - backend depends_on: - db deploy: replicas: 1 update_config: parallelism: 2 delay: 10s restart_policy: condition: on-failure worker: image: dockersamples/examplevotingapp_worker networks: - frontend - backend depends_on: - db - redis deploy: mode: replicated replicas: 1 labels: [APP=VOTING] restart_policy: condition: on-failure delay: 10s max_attempts: 3 window: 120s placement: constraints: [node.role == manager] visualizer: image: dockersamples/visualizer:stable ports: - "8080:8080" stop_grace_period: 1m30s volumes: - "/var/run/docker.sock:/var/run/docker.sock" deploy: placement: constraints: [node.role == manager]
没有评论:
发表评论