我正在使用 Postgres docker 14.4。我想将服务器配置(假设idle_session_timeout
)传递给 postgres docker。文档给出使用 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: [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
可以command
分段传递。更新后的 docker-compose 文件idle_session_timeout
设置为 15 分钟,如下所示
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