Search code examples
postgresqldockerdocker-composetimescaledbwal-e

Error Converting Docker Commands to docker-compose.yml


When trying to translate the following 2 docker commands into a docker-compose.yml using Compose version 3

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

and

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

we get the following error when running docker-compose up:

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

How can we translate the 2 Docker commands correctly to use Compose version 3? We will need to be able to specify the location of the volumes on the host (i.e. ./timescaledb).

Using 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:

Solution

  • In the container timescaledb you are actually mounting the /var/lib/postgresql/data to ./timescaledb and hence, if you want to use the same volume for the wale container, you can edit the wale container like:

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

    In this case, both of the containers will be able to read and write from the same mounted volume to your local machine.

    Also, remember to remove this part as it is not a valid command in docker-compose:

        volumes_from:
          - tsdb