Use docker compose to expose database

The following shell script launches Baserow successfully:

readonly HOST=$(hostname -I | cut -d' ' -f1)
readonly PORT=80

docker run \
  --name baserow \
  -v '/var/lib/docker/volumes/baserow_data/_data':'/baserow/data':'rw' \
  -e 'BASEROW_PUBLIC_URL'="http://${HOST}:${PORT}" \
  -p "80:${PORT}/tcp" \
  -p '447:443/tcp' \
  -p '5432:5432/tcp' \
  --net='bridge' \
  baserow/baserow:latest

Note that the database is mounted locally at /var/lib/docker/volumes/baserow_data/_data and that I’m trying to expose the database port 5432. However, since Baserow uses Unix sockets for PostgreSQL, the port doesn’t get exposed. One recommendation was to use docker compose to expose the database.

The following docker compose file has a few problems:

  • Doesn’t use /var/lib/docker/volumes/baserow_data/_data for the database.
  • Doesn’t use the latest version of PostgreSQL.
  • Doesn’t expose 5432 as the port externally.

I ran docker compose as follows:

export DATABASE_PASSWORD=...
docker-compose up

The docker-compose.yml file contains the following:

version: "3.4"

services:
  db:
    image: postgres:11
    restart: unless-stopped
    environment:
      - POSTGRES_USER=${DATABASE_USER:-baserow}
      - POSTGRES_PASSWORD=${DATABASE_PASSWORD:?}
      - POSTGRES_DB=${DATABASE_NAME:-baserow}
    ports:
      - "5432:5432"
    healthcheck:
      test: [ "CMD-SHELL", "su postgres -c \"pg_isready -U ${DATABASE_USER:-baserow}\"" ]
      interval: 10s
      timeout: 5s
      retries: 5
    volumes:
      - db:/var/lib/docker/volumes/baserow_data/_data

  baserow:
    container_name: baserow
    image: baserow/baserow:latest
    environment:
      BASEROW_PUBLIC_URL: 'http://10.0.1.10'
    ports:
      - "80:80"
      - "443:443"

volumes:
  db:
    driver: local

The error message is:

baserow | Please run baserow with a mounted data folder ‘docker run -v baserow_data:/baserow/data …’, otherwise your data will be lost between runs. To disable this check set the DISABLE_VOLUME_CHECK env variable to ‘yes’ (docker run -e DISABLE_VOLUME_CHECK=yes …).

What needs to change in the docker-compose.yml file to:

  • Point PostgreSQL to the desired host directory (volume)
  • Use the latest version of PostgreSQL (that’s supported by Baserow)
  • Bind port 5432 on the host IP address (e.g., 10.0.1.10)

This is using the latest version of Baserow on Ubuntu 22.

Thank you!

The following works:

version: "3.4"

services:
  db:
    container_name: database
    image: postgres:latest
    restart: unless-stopped
    environment:
      - POSTGRES_USER=${DATABASE_USER:-baserow}
      - POSTGRES_PASSWORD=${DATABASE_PASSWORD:?}
      - POSTGRES_DB=${DATABASE_NAME:-baserow}
      - PGDATA=/var/lib/postgresql/data/pgdata
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data/pgdata

  baserow:
    depends_on:
      - db
    container_name: baserow
    image: baserow/baserow:latest
    environment:
      BASEROW_PUBLIC_URL: "http://10.0.1.10"
      DATABASE_HOST: db
      DATABASE_PORT: 5432
      DATABASE_NAME: ${DATABASE_NAME:-baserow}
      DATABASE_USER: ${DATABASE_USER:-baserow}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD:?}
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - baserow_data:/baserow/data

volumes:
  pgdata:
  baserow_data: