簡體   English   中英

在 docker 容器中替換 postgresql.conf

[英]Replacing postgresql.conf in a docker container

我正在拉取 postgres:12.0-alpine docker 鏡像來構建我的數據庫。 我的目的是替換容器中的 postgresql.conf 文件以反映我想要的更改(更改數據目錄、修改備份選項等)。 我正在嘗試使用以下 docker 文件

FROM postgres:12.0-alpine

# create the custom user 
RUN addgroup -S custom && adduser -S custom_admin -G custom

# create the appropriate directories 
ENV APP_HOME=/home/data 
ENV APP_SETTINGS=/var/lib/postgresql/data 
WORKDIR $APP_HOME

# copy entrypoint.sh 
COPY ./entrypoint.sh $APP_HOME/entrypoint.sh

# copy postgresql.conf 
COPY ./postgresql.conf $APP_HOME/postgresql.conf

RUN chmod +x /home/data/entrypoint.sh

# chown all the files to the app user 
RUN chown -R custom_admin:custom $APP_HOME 
RUN chown -R custom_admin:custom $APP_SETTINGS

# change to the app user 
USER custom_admin

# run entrypoint.sh 
ENTRYPOINT ["/home/data/entrypoint.sh"]

CMD ["custom_admin"]

我的 entrypoint.sh 看起來像

#!/bin/sh

rm /var/lib/postgresql/data/postgresql.conf
cp ./postgresql.conf /var/lib/postgresql/data/postgresql.conf

echo "replaced .conf file"

exec "$@"

但是我收到一個 exec 錯誤,說 'custom_admin: not found on the 'exec "$@"' 行。 我在這里缺少什么?

為了提供自定義配置。 請使用以下命令:

docker run -d --name some-postgres -v "$PWD/my-postgres.conf":/etc/postgresql/postgresql.conf postgres -c 'config_file=/etc/postgresql/postgresql.conf'

這里my-postgres.conf是您的自定義配置文件。

有關 postgres 映像的更多信息,請參閱docker hub 頁面

最好使用@Thilak 的建議答案,您不需要自定義圖像即可使用自定義配置。

現在 Dockerfile 中的CMD ["custom_admin"] custom_admin CMD ["custom_admin"] ,在 Dockerfile 中傳遞給CMD任何命令,您都在入口點的末尾執行該命令,通常此類命令指的是主進程或長時間運行的進程容器。 其中custom_admin看起來像一個用戶,而不是一個命令。 您需要將其替換為將作為容器的主進程運行的進程。

將 CMD 更改為

CMD ["postgres"]

我建議修改開箱即用的執行許多任務的官方入口點,因為您擁有入口點只是啟動容器沒有數據庫初始化等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM