How to Self-Host NocoDB with Docker and Connect It to an Existing PostgreSQL Database
Learn how to deploy NocoDB using Docker and configure it to manage your existing PostgreSQL database for a seamless no-code interface.
Disclosure: this article contains an affiliate link. DotExe may earn a commission if you purchase through it, at no extra cost to you. Any discount is subject to Hostinger's current offers (20% OFF) and eligibility terms.
NocoDB is an open-source platform that turns any database into a smart spreadsheet, providing a powerful no-code interface for your data. If you are looking to self-host NocoDB with Docker and connect it to an existing PostgreSQL instance, you can quickly gain a collaborative UI for your backend data without writing custom admin panels.
Prerequisites
Before starting, ensure you have Docker and Docker Compose installed on your server. If you are looking for a reliable environment to run your containers, you can explore Hostinger Web Hosting to find a suitable hosting plan for your project. You will also need the connection string for your existing PostgreSQL database.
Deploying NocoDB with Docker Compose
To run NocoDB, we will use a docker-compose.yml file. This approach ensures your configuration is reproducible and easy to manage. Create a directory for your project and add the following configuration:
version: "3.8"
services:
nocodb:
image: nocodb/nocodb:latest
ports:
- "8080:8080"
environment:
NC_DB: "pg://<host>:<port>?u=<user>&p=<password>&d=<database>"
volumes:
- ./nocodb_data:/usr/app/data
Replace the placeholders in the NC_DB connection string with your actual PostgreSQL credentials. The NC_DB environment variable tells NocoDB to use your external database for its metadata and data storage rather than the default SQLite file.
Connecting to Your Database
Once you have updated the configuration, start the container by running docker-compose up -d. NocoDB will automatically initialize the necessary tables within your PostgreSQL database the first time it connects.
If you encounter issues during startup, it is often helpful to check the logs using docker-compose logs -f nocodb. Ensure that your PostgreSQL instance allows connections from the IP address of your Docker host. If you are managing complex database workloads, you might also want to monitor PostgreSQL with Netdata to ensure your database performance remains stable as you add more records via the NocoDB interface.
Managing Data
After the container is running, navigate to http://localhost:8080/dashboard in your browser. You will be prompted to create an admin account. Once logged in, you will see your existing PostgreSQL tables reflected in the NocoDB UI. You can now add views, create forms, and share your data with team members without needing to run SQL queries for routine tasks.
Conclusion
Self-hosting NocoDB with Docker provides a flexible way to manage your PostgreSQL data. By pointing NocoDB to an existing database, you keep your data centralized while gaining a powerful, user-friendly interface for your team.
Frequently Asked Questions
Can I use an existing database for NocoDB instead of creating a new one?
Yes, you can connect NocoDB to an existing PostgreSQL database by providing the connection string in the NC_DB environment variable. NocoDB will create its own metadata tables within that database to manage the UI state.
Is it safe to connect NocoDB to a production database?
NocoDB acts as a layer over your database, so it is generally safe provided you manage your database permissions correctly. Ensure the database user provided to NocoDB has the necessary privileges for the operations you intend to perform, but avoid granting unnecessary administrative rights.
How do I update my NocoDB instance?
To update your instance, pull the latest image by running docker-compose pull and then restart your containers with docker-compose up -d. Your data will persist because it is stored in the external PostgreSQL database and the mapped volume.