Git Product home page Git Product logo

pg-docker-server's Introduction

Introduction

This project deploys a simple but secure PostgreSQL instance using Docker with periodic backup to S3.

Setup

  • SSH into your server (Tested on Ubuntu 22.04) and switch to a non-root user.
  • Ensure that you have Docker installed or run
curl -sSL https://get.docker.com | sh
  • Clone this repo into your desired folder.
  • Copy the environment variable sample files using cp app.env.example app.env & cp db.env.example db.env
  • Modify the contents of the app.env files and fill in your credentials as required.
  • Update the default Postgres user credentials and DB in the db.env file.
  • Update values in pgbouncer.env to match your DB credentials.
  • Navigate to PG-Tune enter your server specifications and update the postgresql.conf file. (Default values for a 1vCPU, 2GB RAM VPS).
  • If you wish to enable SSL (strongly recommended if you intend to expose the DB to the internet). Follow the Enable SSL guide below.
  • Run the following to get started
docker compose up -d

Enable SSL

  • While in the project directory, run the following to generate a new self-signed ca key
openssl genrsa 2048 > certs/ca.key 
chmod 600 certs/ca.key
  • Next, run
openssl req -new -nodes -x509 -days 100000 -key certs/ca.key -out certs/ca.cert --server
chmod 600 certs/ca.cert
  • Anytime you are prompted to fill in addtional details to generate certificate, use your server's hostname as the Alias Common Name and fill the other fields as needed.
  • Next, run the following to generate server keys
openssl req -newkey rsa:2048 -nodes -days 100000 -keyout certs/server.key -out certs/server.csr
chmod 600 certs/server.csr
  • Finally, run
openssl x509 -req -days 100000 -set_serial 01 -in certs/server.csr -out certs/server.cert -CA certs/ca.cert -CAkey certs/ca.key
chmod 600 certs/server.cert
  • You can run cat certs/server.cert to copy the file content to use on your client side.
  • Modify the postgresql.conf file to remove the comments from the cert files, uncomment the lines for the certs under postgres -> volume in the docker-compose.yml file, uncomment the last line in the pg_hba.conf file
  • Restart your server if it is running, else start it now.

Additional Notes

You are responsible for implementing measures to properly secure your server. Set up firewall and protect your credentials.

pg-docker-server's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.