0

I am using Postgres docker 14.4. I want to pass a server configuration (let's say idle_session_timeout) to the postgres docker. The doc gives an example using docker run

docker run -d --name test-db -e POSTGRES_PASSWORD=postgres postgres -c idle_session_timeout=900000

How this option can be passed in docker-compose? My docker-compose file now looks like below -

version: '3'
services:
  pgadmin:
    container_name: pgadmin
    image: dpage/pgadmin4
    ports:
      - "6555:80"       # pg admin
      - "6432:6432"     # postgres-db
    environment:
      PGADMIN_DEFAULT_EMAIL: [email protected]
      PGADMIN_DEFAULT_PASSWORD: admin

  postgres-db:
    container_name: test-db
    image: postgres:14.4
    network_mode: "service:pgadmin"
    command: -p 6432
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      PGUSER: postgres
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -p 6432"]
      interval: 5s
      timeout: 5s
      retries: 3

1 Answer 1

0

It can be passed in command section. The updated docker-compose file with idle_session_timeout set to 15 mins is like below

version: '3'
services:
  # IMPORTANT NOTE: All other services will share the network on pgadmin service (network_mode: "service:pgadmin"), so ports need to be opened here instead of other the services.
  # It is added for debugging purpose & may be removed in future when the tests using docker container looks stable
  pgadmin:
    container_name: pgadmin
    image: dpage/pgadmin4
    ports:
      - "6555:80"       # pg admin
      - "6432:6432"     # postgres-db
    environment:
      PGADMIN_DEFAULT_EMAIL: [email protected]
      PGADMIN_DEFAULT_PASSWORD: admin

  postgres-db:
    # Postgres version should be compatible with Aurora:
    # https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Updates.20180305.html
    container_name: test-db
    image: postgres:14.4
    network_mode: "service:pgadmin"
    command: -p 6432 -c idle_session_timeout=900000
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      PGUSER: postgres
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -p 6432"]
      interval: 5s
      timeout: 5s
      retries: 3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .