如何在postgres docker的合成文件中传递idle_session_timeout?

5hcedyr0  于 2023-03-29  发布在  Docker
关注(0)|答案(1)|浏览(130)

我使用的是Postgres docker 14.4,我想为我的postgres docker设置idle_session_timeout,文档给出了使用docker run的示例

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

如何在docker-compose中传递此选项?我的docker-compose文件现在看起来像下面-

version: '3'
services:
  pgadmin:
    container_name: pgadmin
    image: dpage/pgadmin4
    ports:
      - "6555:80"       # pg admin
      - "6432:6432"     # postgres-db
    environment:
      PGADMIN_DEFAULT_EMAIL: pgadmin4@pgadmin.org
      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
nxowjjhe

nxowjjhe1#

它可以在command节中传递。将idle_session_timeout设置为15分钟的更新后的docker-compose文件如下所示

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: pgadmin4@pgadmin.org
      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

相关问题