我正在使用postgres官方图像
https://registry.hub.docker.com/_/postgres/.现在我正在尝试自定义其配置。为此,使用命令sed,例如更改max_connections:
sed -i -e“s / ^ max_connections = 100。* $ / max_connections = 1000 /”/var/lib/postgresql/data/postgresql.conf
sed -i -e“s / ^ max_connections = 100。* $ / max_connections = 1000 /”/var/lib/postgresql/data/postgresql.conf
我尝试了两种方法来应用此配置。第一个是将命令添加到脚本中,并将其复制到init文件夹“/docker-entrypoint-initdb.d”中。第二种方法是使用“RUN”命令直接在Dockerfile中运行它(此方法对于具有与配置文件“/ etc / postgres / …”不同的路径)的非官方postgresql映像运行正常。在这两种情况下,更改失败,因为配置文件丢失(我还没有创建)。
我应该如何更改配置?
编辑1:
以下是用于创建映像的Dockerfile:
# Database (http://www.cs3c.ma/) FROM postgres:9.4 MAINTAINER Sabbane <contact@cs3c.ma> ENV TERM=xterm RUN apt-get update RUN apt-get install -y nano ADD scripts /scripts # ADD scripts/setup-my-schema.sh /docker-entrypoint-initdb.d/ # Allow connections from anywhere. RUN sed -i -e"s/^#listen_addresses =.*$/listen_addresses = '*'/" /var/lib/postgresql/data/postgresql.conf RUN echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/data/pg_hba.conf # Configure logs RUN sed -i -e"s/^#logging_collector = off.*$/logging_collector = on/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#log_directory = 'pg_log'.*$/log_directory = '\/var\/log\/postgresql'/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#log_filename = 'postgresql-\%Y-\%m-\%d_\%H\%M\%S.log'.*$/log_filename = 'postgresql_\%a.log'/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#log_file_mode = 0600.*$/log_file_mode = 0644/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#log_truncate_on_rotation = off.*$/log_truncate_on_rotation = on/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#log_rotation_age = 1d.*$/log_rotation_age = 1d/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#log_min_duration_statement = -1.*$/log_min_duration_statement = 0/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#log_checkpoints = off.*$/log_checkpoints = on/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#log_connections = off.*$/log_connections = on/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#log_disconnections = off.*$/log_disconnections = on/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^log_line_prefix = '\%t \[\%p-\%l\] \%q\%u@\%d '.*$/log_line_prefix = '\%t \[\%p\]: \[\%l-1\] user=\%u,db=\%d'/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#log_lock_waits = off.*$/log_lock_waits = on/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#log_temp_files = -1.*$/log_temp_files = 0/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#statement_timeout = 0.*$/statement_timeout = 1800000 # in milliseconds,0 is disabled (current 30min)/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^lc_messages = 'en_US.UTF-8'.*$/lc_messages = 'C'/" /var/lib/postgresql/data/postgresql.conf # Performance Tuning RUN sed -i -e"s/^max_connections = 100.*$/max_connections = 1000/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^shared_buffers =.*$/shared_buffers = 16GB/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#effective_cache_size = 128MB.*$/effective_cache_size = 48GB/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#work_mem = 1MB.*$/work_mem = 16MB/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#maintenance_work_mem = 16MB.*$/maintenance_work_mem = 2GB/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#checkpoint_segments = .*$/checkpoint_segments = 32/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#checkpoint_completion_target = 0.5.*$/checkpoint_completion_target = 0.7/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#wal_buffers =.*$/wal_buffers = 16MB/" /var/lib/postgresql/data/postgresql.conf RUN sed -i -e"s/^#default_statistics_target = 100.*$/default_statistics_target = 100/" /var/lib/postgresql/data/postgresql.conf VOLUME ["/var/lib/postgresql/data","/var/log/postgresql"] CMD ["postgres"]
使用这个Dockerfile,构建过程显示错误:sed:无法读取/var/lib/postgresql/data/postgresql.conf:没有这样的文件或目录
Postgres:9.4您继承的图像在/var/lib/postgresql / data中声明一个卷。这实际上意味着你无法将任何文件复制到图像中的路径上;更改将被丢弃。
原文链接:https://www.f2er.com/postgresql/193054.html你有几个选择:
>您可以在运行时将自己的配置文件作为一个卷添加到docker run -v postgresql.conf:/var/lib/postgresql/data/postgresql.conf ….但是,我不知道如何这将与现有卷交互。>容器启动时可以复制文件。要做到这一点,将文件复制到不在卷轴下方的位置,然后从entrypoint或cmd调用脚本,将脚本复制到正确的位置并启动postgres。>克隆Postgres官方图像背后的项目,并编辑Dockerfile,在声明VOLUME之前添加自己的配置文件(在运行时自动复制VOLUME指令之前添加的任何内容)。