A
A
Anton Shvets2016-05-25 18:28:51
Docker
Anton Shvets, 2016-05-25 18:28:51

How to move postgres configuration to docker mounted volume?

I am building my postgres, according to the manual in the docker docks.
docker build -t my/postgres .

FROM ubunru
RUN apt-get install -y python-software-properties software-properties-common postgresql-9.5 postgresql-client-9.5 postgresql-contrib-9.5
USER postgres
RUN    /etc/init.d/postgresql start &&\
    psql --command "CREATE USER myuser WITH SUPERUSER PASSWORD 'pmyuser';" &&\
    createdb -O myuser myuser
RUN echo "host all  all    0.0.0.0/0  md5" >> /etc/postgresql/9.5/main/pg_hba.conf
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.5/main/postgresql.conf
EXPOSE 5432
VOLUME  ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
ENTRYPOINT /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c config_file=/etc/postgresql/9.5/main/postgresql.conf

launching
docker run -d --name=PGmaster \
 -p 5432:5432 \
 -v /opt/postgres/etc:/etc/postgresql/9.5/main \
 -v /opt/postgres/log:/var/log/postgresql \
 -v /opt/postgres/data:/var/lib/postgresql \
  my/postgres

Postgres says configs not found. Well, yes, mounting is performed after the container is assembled and it overwrites the existing files.
How it is better to return to it a config?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
de1m, 2016-06-01
@Xuxicheta

I had something similar with "mysql". There are five solutions here:
1. Use the official container, maybe this problem has already been solved there and link it to where you need postgres
2. You already have a ready-made config and you upload it during container creation via "COPY" or " ADD"
3. Make a script (Place in ENTRYPOINT) that will check a specific folder. If the folder exists and it is empty, then copy the config there and postgres starts from it, if there is no folder, then it starts from the original config. It turns out that during assembly it will use the original config, and at startup it will be necessary to mount the folder (which will be checked in the script). The script will drop the config there and will use it for the next starts.(run.sh) but hell is there. There's a bunch of other things for mysql and icinga.
4. Use "sed" and change / add the necessary settings to /etc/postgresql/9.5/main/postgresql.conf
5. If you don't have any special settings, then what for then touch it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question