docker swarm 健康管理
health check在swarm中应用
mkdir mynginx cd mynginx/ vi Dockerfile 写入以下内容 FROM 192.168.172.128:5000/centos7 RUN yum -y install epel-release RUN yum -y install nginx COPY index.html /usr/share/nginx/html EXPOSE 80 CMD ["nginx","-g","daemon off;"]
docker build -t 192.168.172.128:5000/mynginx . docker run -dit --name test --health-cmd "curl --fail http://localhost/ || exit 1" --health-timeout 5s --health-interval 8s -p 80 192.168.172.128:5000/mynginx
模拟不健康
docker run -dit --name test2 --health-cmd "curl --fail http://localhost/opexit || exit 1" --health-timeout 5s --health-interval 8s -p 80 192.168.172.128:5000/mynginx
创建secret
openssl rand -base64 20 | docker secret create my_secret2 - openssl rand -base64 20 > password.txt docker secret create my_secret3 password.tx
创建自定义的overlay网络
docker network create -d overlay my_priv
创建mysql service
docker service create --name wpmysql --network my_priv --secret source=my_secret2,target=mysql_root_password --secret source=my_secret3,target=mysql_user_password -e MYSQL_ROOT_PASSWORD_FILE="/run/secrets/mysql_root_password" -e MYSQL_PASSWORD_FILE="/run/secrets/mysql_user_password" -e MYSQL_USER="wordpress" -e MYSQL_DATABASE="wordpress" 192.168.172.128:5000/mysql
验证: