Getting started with Nile's Postgres platform locally with Docker
Nile provides a cloud offering to help build multi-tenant apps. You can also get started with Nile’s Docker image and try Nile locally. Join our discord to give feedback or ask questions about running Nile locally.
Prerequisites
- Docker
- Postgres client. We’ll use
psql
in this guide.
Run the Docker Container
This will start a Postgres database with Nile extensions installed.
If this is the first time you are running the container, it will also pull the latest image,create the test
database
and the 00000000-0000-0000-0000-000000000000
user.
Connecting to the Database
You can use psql
with the following connection string:
Or, if you are using a different client, you use the following connection details:
Using the local database
From this point, you can use the local database just like you would use Nile service. All the examples in the documentation are also applicable to the local database. Below we’ll go through the steps in the quickstart guide using the local database.
Create a tenant-aware table
Tenant-aware tables are tables that have
a tenant_id
column. All the rows in such tables belong to a specific tenant.
Let us create our first table that has a tenant_id column and a vector column:
If you are using psql
, you can view the table schema by running \d todos
.
Create tenants
Nile ships with built-in tables, like tenants
table. Lets create our first tenant by inserting a row into the tenants
table:
Insert data into a tenant-aware table
Now that we have a tenant, we can insert data into our tenant-aware table:
and you can verify the data was inserted correctly by running:
You can add another tenant and insert data for that tenant in a similar fashion. This will allow us to explore tenant isolation (in the next section).
Tenant isolation
Nile goes a step further and provides tenant isolation. You can set the session to a specific tenant, and every query that follows will only return data that belongs to this specific tenant.
Think of it as querying a virtual database dedicated to this one specific tenant.
✏️ Note that the container uses ephemeral storage, so all the data will be lost when the container is stopped. This is intentional, as it simplifies the setup (and more importantly - the cleanup), while still allowing you to experiment and test your application.
Looking good! What’s next?
🏆 Tada! You have learned the key Nile concepts. And it only took 5 minutes.
You can learn more about Nile’s tenant virtualization features in the following tutorials:
Next, you will probably want to learn how to use Nile for building an app in your favorite language. Check out our Getting Started guides for more information.
Optional: Docker container configuration
The docker container can be configured with the following environment variables:
NILE_TESTING_DB_NAME
: The name of the database. Defaults totest
.NILE_TESTING_DB_ID
: The ID of the database. Must be a UUID. Defaults to00000000-0000-0000-0000-000000000000
.NILE_TESTING_DB_USER
: The username for the database user. Must be UUID. Defaults to00000000-0000-0000-0000-000000000000
.NILE_TESTING_DB_PASSWORD
: The password of the database user. Defaults topassword
.
If you need to change the default values, you can do so by setting the environment variables when running the container.
with this configuration, the connection string will be:
You can also change the port mappings in the docker run command, if you want Postgres to listen on a different port.
Was this page helpful?