PostgrSQL custom Docker Container

0 votes

I'm attempting to create a Docker entrypoint script that will start PostgreSQL and create a new named database.

There seems to be a lot better way than mine. Every contribution makes me delighted.

My issues:

1. I've had to restart the container a few times before it generates the database and doesn't crash. I'm not always sure why it works. I'm having trouble recreating it right now.
2. I frequently receive email with the subject line [unknown]@[unknown]. LOG: There should be no startup packet, yet there is.


I need PostgreSQL to use ssl for every connection, therefore I created a special docker image for that. Unfortunately, the official picture does not support SSL with actual certificates.

The dockerfile:

FROM debian:10.9

RUN apt update && apt install -y \
    postgresql postgresql-contrib \
    openssl \
    net-tools netcat \
    vim

RUN mkdir database_stuff

COPY --chown=postgres:postgres ./entrypoint.sh /database_stuff/entrypoint.sh
RUN chmod 777 /database_stuff/entrypoint.sh

COPY --chown=postgres:postgres ./certificates/cert.pem /database_stuff/cert.pem
RUN chmod 600 /database_stuff/cert.pem
COPY --chown=postgres:postgres ./certificates/key.pem /database_stuff/key.pem
RUN chmod 600 /database_stuff/key.pem

COPY --chown=postgres:postgres ./configuration/postgresql.conf /etc/postgresql/11/main/postgresql.conf
COPY --chown=postgres:postgres ./configuration/pg_hba.conf /etc/postgresql/11/main/pg_hba.conf

VOLUME  ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]

USER postgres

CMD ["/usr/lib/postgresql/11/bin/postgres", "-D", "/var/lib/postgresql/11/main/", "-c", "config_file=/etc/postgresql/11/main/postgresql.conf"]

ENTRYPOINT ["/database_stuff/entrypoint.sh"]

script for entrypoint.sh

#!/usr/bin/env bash
echo "START entrypoint.sh"

echo "start postgrSQL"
/usr/lib/postgresql/11/bin/postgres -D /var/lib/postgresql/11/main/ -c config_file=/etc/postgresql/11/main/postgresql.conf &

until nc -z db 5432; do
  sleep 0.1
done

echo "create Database"
psql -U postgres -c 'create database part_screening;'
psql -U postgres -c "create user alstom with encrypted password 'Laser765_f';"

echo "END entrypoint.sh .... Stay open"
tail -f /dev/null

a log with unknown@unknown issue

START entrypoint.sh

start postgrSQL

create Database

CREATE DATABASE

CREATE ROLE

END entrypoint.sh .... Stay open


2021-08-02 17:08:52.280 UTC [7] LOG: listening on IPv4 address "0.0.0.0", port 5432

2021-08-02 17:08:52.280 UTC [7] LOG: listening on IPv6 address "::", port 5432

2021-08-02 17:08:52.284 UTC [7] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"

2021-08-02 17:08:52.300 UTC [10] LOG: database system was shut down at 2021-08-02 17:06:42 UTC

2021-08-02 17:08:52.305 UTC [7] LOG: database system is ready to accept connections

2021-08-02 17:08:52.330 UTC [18] [unknown]@[unknown] LOG: incomplete startup packet

2021-08-02 17:08:53.145 UTC [38] [unknown]@[unknown] LOG: incomplete startup packet
Apr 30, 2022 in Docker by Abhijeet
• 180 points

edited 4 days ago 4 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP