Score:0

How to pass server configuration to postgres docker via a compose file?

ng flag
tuk

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
Score:0
ng flag
tuk

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
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.