在泊坞窗群集群中,有一个主人和两个工人。
在主控主机上创建一个yaml文件:
stack.yml
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_PASSWORD: example
mysql:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
$ docker stack deploy -c stack.yml wordpress
检查主人:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f24d160ef788 wordpress:latest "docker-entrypoint.s…" 19 seconds ago Up 13 seconds 80/tcp wordpress_wordpress.1.5rilktpp43xtv1avtmp0uuh0u
# This is I downloaded the images myself:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wordpress latest c649c99a766e 12 hours ago 408MB
mysql 5.7 0d16d0a97dd1 2 weeks ago 372MB
$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
ra3wfcq8owmb wordpress_mysql replicated 1/1 mysql:5.7
hosko1vl55wq wordpress_wordpress replicated 1/1 wordpress:latest *:8080->80/tcp
检查worker1主机:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f91c127d6166 wordpress:latest "docker-entrypoint.s…" 12 seconds ago Up 10 seconds 80/tcp wordpress_wordpress.1.98fkpvprkdjwkdik2hieqcg7g
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wordpress <none> c649c99a766e 12 hours ago 408MB
检查worker2主机:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6465e16ee5b4 0d16d0a97dd1 "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp wordpress_mysql.1.xhrfekxylgycyp0qf6ca7h9ok
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wordpress <none> c649c99a766e 12 hours ago 408MB
无法从http://[IP]:8080访问。
$ docker-compose -f stack.yml up
效果很好。
docker stack ...
部署了没有在所有群集主机上提取图像?docker-compose
方式可以?docker-compose
方式是否也在整个群集群上部署容器?(更改IP)
$ docker service logs -f wordpress_wordpress
wordpress_wordpress.1.yiowxbsrup5v@ip-1-2-3-4.ap-northeast-1.compute.internal |
wordpress_wordpress.1.yiowxbsrup5v@ip-1-2-3-4.ap-northeast-1.compute.internal | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in Standard input code on line 22
wordpress_wordpress.1.yiowxbsrup5v@ip-1-2-3-4.ap-northeast-1.compute.internal |
wordpress_wordpress.1.yiowxbsrup5v@ip-1-2-3-4.ap-northeast-1.compute.internal | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
wordpress_wordpress.1.yiowxbsrup5v@ip-1-2-3-4.ap-northeast-1.compute.internal |
wordpress_wordpress.1.yiowxbsrup5v@ip-1-2-3-4.ap-northeast-1.compute.internal | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in Standard input code on line 22
wordpress_wordpress.1.yiowxbsrup5v@ip-1-2-3-4.ap-northeast-1.compute.internal |
wordpress_wordpress.1.yiowxbsrup5v@ip-1-2-3-4.ap-northeast-1.compute.internal | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in Standard input code on line 22
wordpress_wordpress.1.yiowxbsrup5v@ip-1-2-3-4.ap-northeast-1.compute.internal |
wordpress_wordpress.1.yiowxbsrup5v@ip-1-2-3-4.ap-northeast-1.compute.internal | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal | WordPress not found in /var/www/html - copying now...
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal | Complete! WordPress has been successfully copied to /var/www/html
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal |
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in Standard input code on line 22
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal |
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal |
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in Standard input code on line 22
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal |
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in Standard input code on line 22
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal |
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in Standard input code on line 22
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal |
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal |
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in Standard input code on line 22
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal |
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in Standard input code on line 22
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal |
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal |
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in Standard input code on line 22
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal |
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in Standard input code on line 22
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal |
wordpress_wordpress.1.ei7e4zio6rj1@ip-1-2-3-5.ap-northeast-1.compute.internal | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
无法连接到mysql。