openssl req -new -509 -days 365 -nodes -text -out server.crt (n -keyout server key -subj "/CN=localhost"
Run the following commands to copy cert files to the container and update permissions:
docker cp server.crt «CONTAINER_ID>:/var/lib/pgsql/data/userdata/
docker cp server. key «CONTAINER_ID>:/var/lib/pgsql/data/userdata/
docker exec -u 0 -it «CONTAINER_ ID> chown postgres:postgres /var/lib/pgsql/data/userdata/server.crt
docker exec -u 0 -it «CONTAINER ID> chown postgres:postgres /var/lib/pgsql/data/userdata/server.key
docker exec -u 0 -it «CONTAINER ID» chmod og-rwx /var/11b/pgsql/data/userdata/server.key
Login to the postgres docker container
docker exec -it «CONTAINER_ ID> bash
Update the following SSL config in /var/lib/postgresql/data/postgresql.conf
ssl = on
ssl_cert_file = server.crt
ssl_key_file = server.key
Restart the postgres container.