![](/img/trans.png)
[英]Increase /dev/shm in docker container in swarm environment (docker stack deploy)
[英]Docker stack deploy postgresql slave container restart in few minutes
在Swarm中使用docker stack运行此YML。 Docker堆栈文件以创建具有2个从属的Postgresql主/从设置。
从属容器将在几分钟内重新启动并重复执行。
如何解决?
docker stack deploy -c docker-stack-postgresql.yml post
docker-stacl-postgresql.yml
<pre>version: "3"
services:
db1:
image: bitnami/postgresql:latest
ports:
- "127.0.0.1:5432:5432"
networks:
- awesomenet
deploy:
placement:
constraints: [node.hostname == node-docker-1]
volumes:
- pgdata:/bitnami/postgresql
env_file: .env.master
db2:
image: bitnami/postgresql:latest
depends_on:
- db1
ports:
- "127.0.0.1:5433:5432"
networks:
- awesomenet
deploy:
placement:
constraints: [node.hostname == node-docker-2]
volumes:
- pgdata:/bitnami/postgresql
env_file: .env.slave
db3:
image: bitnami/postgresql:latest
depends_on:
- db1
ports:
- "127.0.0.1:5434:5432"
networks:
- awesomenet
deploy:
placement:
constraints: [node.hostname == node-docker-3]
volumes:
- pgdata:/bitnami/postgresql
env_file: .env.slave
volumes:
pgdata:
networks:
awesomenet:
driver: overlay
driver_opts:
encrypted: "true"
</pre>
主环境文件:.env.master
<pre>
POSTGRESQL_REPLICATION_MODE=master
POSTGRESQL_REPLICATION_USER=replication_user
POSTGRESQL_REPLICATION_PASSWORD= replication_password
POSTGRESQL_USERNAME=postgres
POSTGRESQL_PASSWORD=password
POSTGRESQL_DATABASE=monkey_db
</pre>
环境文件:.env.slave
<pre>
POSTGRESQL_REPLICATION_MODE=slave
POSTGRESQL_REPLICATION_USER=replication_user
POSTGRESQL_REPLICATION_PASSWORD= replication_password
POSTGRESQL_MASTER_HOST=db1
POSTGRESQL_MASTER_PORT=5432
</pre>
PostgreSQL日志文件:
<pre>
nami INFO Initializing postgresql
postgre INFO This installation requires no credentials.
nami INFO postgresql successfully initialized
</pre>
PostgreSQL error.log
<pre>
2018-01-16T00:22:47.426512118Z Starting postgresql...
2018-01-16T00:26:11.369732522Z ERROR Unable to start com.bitnami.postgresql: pg_ctl: directory "/opt/bitnami/postgresql/data" is not a database cluster directory
</pre>
这为我工作:
version: "3"
services:
db1:
image: bitnami/postgresql:latest
volumes:
- pgdata:/bitnami/postgresql
env_file: .env.master
db2:
image: bitnami/postgresql:latest
env_file: .env.slave
db3:
image: bitnami/postgresql:latest
env_file: .env.slave
volumes:
pgdata:
因此,您可能试图对所有三个服务使用相同的卷。 因此,要么1.为每个卷创建一个不同的命名卷,要么2.不要为db2 / 3使用卷,因为它们只是主数据库的副本。
另外,不需要使用depends_on,它在Swarm Stacks中不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.