gpt4 book ai didi

postgresql - 将Docker命令转换为docker-compose.yml时出错

转载 作者:行者123 更新时间:2023-12-02 18:50:48 31 4
gpt4 key购买 nike

尝试使用Compose版本3将以下2个docker命令转换为docker-compose.yml

docker run​ \
--name timescaledb \
--network timescaledb-net \
-e POSTGRES_PASSWORD=insecure \
-e POSTGRES_INITDB_WALDIR=/var/lib/postgresql/data/pg_wal \
-e PGDATA=/var/lib/postgresql/data/pg_data \
timescale/timescaledb:latest-pg11 postgres \
-cwal_level=archive \
-carchive_mode=on \
-carchive_command="/usr/bin/wget wale/wal-push/%f -O -" \
-carchive_timeout=600 \
-ccheckpoint_timeout=700 \
-cmax_wal_senders=1


docker run​ \
--name wale \
--network timescaledb-net \
--volumes-from timescaledb \
-v ./backups:/backups \
-e WALE_LOG_DESTINATION=stderr \
-e PGWAL=/var/lib/postgresql/data/pg_wal \
-e PGDATA=/var/lib/postgresql/data/pg_data \
-e PGHOST=timescaledb \
-e PGPASSWORD=insecure \
-e PGUSER=postgres \
-e WALE_FILE_PREFIX=file://localhost/backups \
timescale/timescaledb-wale:latest

我们在运行 docker-compose up时遇到以下错误:

ERROR: The Compose file './docker-compose.yml' is invalid because: Unsupported config option for services.wale: 'volumes_from'



我们如何正确转换2个Docker命令以使用Compose版本3?我们将需要能够指定卷在主机上的位置(即 ./timescaledb)。

使用Mac OS X 10.15.3,Docker 19.03.8,Docker Compose 1.25.4

docker-compose.yml
version: '3.3'
services:
timescaledb:
image: timescale/timescaledb:latest-pg11
container_name: timescaledb
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD=insecure
- POSTGRES_INITDB_WALDIR=/var/lib/postgresql/data/pg_wal
- PGDATA=/var/lib/postgresql/data/pg_data
command: -cwal_level=archive -carchive_mode=on -carchive_command="/usr/bin/wget wale/wal-push/%f -O -" -carchive_timeout=600 -ccheckpoint_timeout=700 -cmax_wal_senders=1
volumes:
- ./timescaledb:/var/lib/postgresql/data
networks:
- timescaledb-net

wale:
image: timescale/timescaledb-wale:latest
container_name: wale
environment:
- WALE_LOG_DESTINATION=stderr
- PGWAL=/var/lib/postgresql/data/pg_wal
- PGDATA=/var/lib/postgresql/data/pg_data
- PGHOST=timescaledb
- PGPASSWORD=insecure
- PGUSER=postgres
- WALE_FILE_PREFIX=file://localhost/backups
volumes_from:
- tsdb
volumes:
- ./backups:/backups
networks:
- timescaledb-net
depends_on:
- timescaledb

networks:
timescaledb-net:

最佳答案

timescaledb容器中,您实际上是在将/var/lib/postgresql/data挂载到./timescaledb,因此,如果要将相同的卷用于wale容器,则可以编辑wale容器,如下所示:

...
volumes:
- ./backups:/backups
- ./timescaledb:/var/lib/postgresql/data
...

在这种情况下,两个容器都将能够从相同的安装卷读取和写入本地计算机。

另外,请记住删除此部分,因为它在docker-compose中不是有效命令:
    volumes_from:
- tsdb

关于postgresql - 将Docker命令转换为docker-compose.yml时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60879866/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com