docker stack利用secrets启动wordpress

docker-compose文件

version: '3.6'

services:

  web:
    image: wordpress
    ports:
      - 8080:80
    secrets:
      - my-pw
    environment:
      WORDPRESS_DB_HOST: mysql
      WORDPRESS_DB_PASSWORD_FILE: /run/secrets/my-pw
    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
    secrets:
      - my-pw
    environment:
      MYSQL_ROOT_PASSWORD_FILE: /run/secrets/my-pw
      MYSQL_DATABASE: wordpress
    volumes:
      - mysql-data:/var/lib/mysql
    networks:
      - my-network
    deploy:
      mode: global
      placement:
        constraints:
          - node.role == manager

volumes:
  mysql-data:

networks:
  my-network:
    driver: overlay

secrets:
  my-pw:
    external: true

创建secret

echo "password" | docer secret create my-pw -

(也可用docker secret create my-pw password)

直接运行docker stack

docker stack deploy wordpress -c=docker-compose.yml

 

查看现在有几个docker stack

[root@230 stack]# docker stack ls
NAME                SERVICES            ORCHESTRATOR
wordpress           2                   Swarm

  

查看具体的docker stack信息

[root@230 stack]# docker stack ps wordpress
ID                  NAME                                        IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
sc6esctq00s7        wordpress_mysql.5dj3gvs99y8pd5wpbiywnlzgi   mysql:latest        230                 Running             Running 12 minutes ago                       
q9vtyylkkweo        wordpress_web.1                             wordpress:latest    231                 Running             Running 12 minutes ago                       
1n67rchcksfc        wordpress_web.2                             wordpress:latest    232                 Running             Running 12 minutes ago                       
58jay8st78g5        wordpress_web.3                             wordpress:latest    230                 Running             Running 12 minutes ago   

 

查看到web节点部署在230,231,232,任意选取一台浏览器打开http://192.168.199.231:8080/即可安装

posted @ 2019-09-30 01:27  豆浆D  阅读(304)  评论(0编辑  收藏  举报