version: "3"
services:
mysql:
container_name: login_db
image: mysql:5.7
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=123456
volumes:
- "mysql-data:/var/lib/mysql"
networks:
- my-bridge
volumes:
mysql-data:
networks:
my-bridge:
driver: bridge
docker-compose -f /path/to/script.yml up --scale orderService=3 -d
-
不能夠指定 container_name,即容器名;
-
不能夠指定埠對映關係;
-
不能夠指定掛載資料捲或目錄。
docker swarm init --advertise-addr=本機IP
Swarm initialized: current node (gmdscjfdlubanwl7i75z5cc85) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-6djatxtetutac68xd1u8v1icnyv6t0pcplhaph2irqqxqo1m2b-8w6lq2kpw6j1chqpu4vlf2cx3 \
管理節點IP:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
gmdscjfdlubanwl7i75z5cc85 * docker-1 Ready Active Leader
xna7a0h6a0xhct95kh7v6p9pl docker-3 Ready Active
docker node update --label-add mytag=db xna7a0h6a0xhct95kh7v6p9pl
docker service create --name mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7
ID NAME IMAGE NODE ESIRED STATE CURRENT STATE ERROR PORTS
0m5erytxi6sa mysql.1 mysql:5.7 docker-1 Running Running 3 minutes ago
docker service scale mysql=3
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
0m5erytxi6sa mysql.1 mysql:5.7 docker-1 Running Running 13 minutes ago
idgvqymekwam mysql.2 mysql:5.7 docker-3 Running Running 3 minutes ago
fldlrega7p40 mysql.3 mysql:5.7 docker-3 Running Running 3 minutes ago
docker service update --image mysql:5.8 mysql
version: '3'
services:
wordpress:
image: wordpress
ports:
- 80: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.labels.mytag == db]
volumes:
mysql-data:
networks:
my-network:
driver: overlay
docker network create -d overlay my-network
networks:
my-network:
external: true
docker stack deploy -c myweb.yml myweb