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

Error Converting Docker Commands to docker-compose.yml

当尝试使用 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 合成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