简体   繁体   English

在 docker 容器中替换 postgresql.conf

[英]Replacing postgresql.conf in a docker container

I am pulling the postgres:12.0-alpine docker image to build my database.我正在拉取 postgres:12.0-alpine docker 镜像来构建我的数据库。 My intention is to replace the postgresql.conf file in the container to reflect the changes I want (changing data directory, modify backup options etc).我的目的是替换容器中的 postgresql.conf 文件以反映我想要的更改(更改数据目录、修改备份选项等)。 I am trying with the following docker file我正在尝试使用以下 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"]

my entrypoint.sh looks like我的 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 "$@"

But I get an exec error saying 'custom_admin: not found on the 'exec "$@"' line.但是我收到一个 exec 错误,说 'custom_admin: not found on the 'exec "$@"' 行。 What am I missing here?我在这里缺少什么?

In order to provide a custom configuration.为了提供自定义配置。 Please use the below command:请使用以下命令:

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

Here my-postgres.conf is your custom configuration file.这里my-postgres.conf是您的自定义配置文件。

Refer the docker hub page for more information about the postgres image.有关 postgres 映像的更多信息,请参阅docker hub 页面

Better to use the suggested answer by @Thilak, you do not need custom image to just use the custom config.最好使用@Thilak 的建议答案,您不需要自定义图像即可使用自定义配置。

Now the problem with the CMD ["custom_admin"] in the Dockerfile, any command that is passed to CMD in the Dockerfile, you are executing that command in the end of the entrypoint, normally such command refers to main or long-running process of the container.现在 Dockerfile 中的CMD ["custom_admin"] custom_admin CMD ["custom_admin"] ,在 Dockerfile 中传递给CMD任何命令,您都在入口点的末尾执行该命令,通常此类命令指的是主进程或长时间运行的进程容器。 Where custom_admin seems like a user, not a command.其中custom_admin看起来像一个用户,而不是一个命令。 you need to replace this with the process which would run as a main process of the container.您需要将其替换为将作为容器的主进程运行的进程。

Change CMD to将 CMD 更改为

CMD ["postgres"]

I would suggest modifying the offical entrypoint which do many tasks out of the box, as you own entrypoint just starting the container no DB initialization etc.我建议修改开箱即用的执行许多任务的官方入口点,因为您拥有入口点只是启动容器没有数据库初始化等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM