docker stack利用secrets启动wordpress

Posted soymilk2019

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker stack利用secrets启动wordpress相关的知识,希望对你有一定的参考价值。

docker-compose文件

version: 3.1

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 create wordpress -c=docker-compose.yml

 

 

以上是关于docker stack利用secrets启动wordpress的主要内容,如果未能解决你的问题,请参考以下文章

Docker Zero Deployment and Secrets

stack 的优势 - 每天5分钟玩转 Docker 容器技术(113)

docker-compose,容器启动后运行脚本?

如何使用 Secret?- 每天5分钟玩转 Docker 容器技术(108)

Swarm stack

Docker Compose与Docker Stack的不同之处