Deploy your PostgreSQL Database in a Docker container on a NAS Synology

Julien Milon
bioMKNX
Published in
4 min readOct 28, 2022

In this story I explain how to deploy a PostgresSQL Database on your NAS Synology with Docker, for any needs such:

Prerequisites for this story :

Build your Docker container with PostgreSQL Database

Charge postgis/postgis image on Docker

https://registry.hub.docker.com/r/postgis/postgis/

  • Open Docker on your NAS Synology.
  • Go on Repository Tab and search postgis/postgis.
  • Select and charge the version that you want.

Now you should see the image on Images Tab.

Run your Docker container with postgis/postgis image

  • Double click on postgis/postgis Image
  • Select Bridge Network
  • Name your container.
  • Give a limite of space if you want it. Optional
  • Select “Enable automatic restart”.
  • Click on “Advanced Parameters” to define your password and your username
  • Add 2 variables, POSTGRES_USER and POSTGRES_PASSWORD and define their value. For me POSTGRES_USER did not work, and the default user is postgres. The USER is maybe in Run command Tab but I did not try it
  • Save
  • Define the port that you want to use. Do not 5432 and other used port.
  • To save your data in your NAS Synology and not loss it when the container stop or restart define a Share volume. The first folder is the folder on your NAS Synology Files and add in “Access path” /var/lib/postgresql/data
  • Execute

You may need to define a rule on your internet Box to to root to your Synology NAS if you connect to the chosen port on your internet box.

Public IP address : port — > NAS Synology : port

Get access to your database with Pgadmin 4

  • Download pgAdmin 4 on your computer (https://www.pgadmin.org/download/pgadmin-4-windows/ for Windows).
  • If it the first time that you use it define the password of your pgAdmin.
  • Click right on “Server”, than click on “Register — > Server…”
  • Define the name that you want for this server connection.
  • Go on “Connection” Tab to add your Database information.
  • Host is your IP Public address
  • Port is the port that your used on your Docker container
  • Maintenance database and Username are the User that you add on the container parameters. By default it is “postgres”
  • Add your Password that you define with POSTGRES_PASSWORD
  • And Save

You now have access to your Database with pgAdmin. You can also connect with any programming language and their IDE such with R programming language and RStudio or Python with Jupiter Notebook or PyCharm ,...

In connection with another story that I wrote (https://medium.com/@julienmilon/deploy-your-website-using-golem-shiny-docker-on-nas-synology-1b4df0e9cbd4), you could use this database to connect it to a website that you have or want to deploy on your Synology NAS, to have application logs, in user bases or even in data sources …

--

--