Skip to content

Instantly share code, notes, and snippets.

@gigawhitlocks
Forked from mrw34/postgres.sh
Created January 23, 2020 00:52
Show Gist options
  • Save gigawhitlocks/69e2ccf94f737218e45d73a3bf3528c6 to your computer and use it in GitHub Desktop.
Save gigawhitlocks/69e2ccf94f737218e45d73a3bf3528c6 to your computer and use it in GitHub Desktop.
Enabling SSL for PostgreSQL in Docker
#!/bin/bash
set -euo pipefail
openssl req -new -text -passout pass:abcd -subj /CN=localhost -out server.req -keyout privkey.pem
openssl rsa -in privkey.pem -passin pass:abcd -out server.key
openssl req -x509 -in server.req -text -key server.key -out server.crt
chmod 600 server.key
test $(uname -s) == Linux && echo chown 70 server.key
docker run -d --name postgres -v "$(pwd)/server.crt:/var/lib/postgresql/server.crt:ro" -v "$(pwd)/server.key:/var/lib/postgresql/server.key:ro" postgres:12-alpine -c ssl=on -c ssl_cert_file=/var/lib/postgresql/server.crt -c ssl_key_file=/var/lib/postgresql/server.key
sleep 1
docker run --rm -it --link postgres postgres:12-alpine psql -h postgres -U postgres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment