Overview
When you develop in Docker, you can connect a database to your Mage container. This allows you to use the database in your data pipelines. A Docker Network is a virtual network that allows containers to communicate with each other. By creating a network, you can connect database containers to your Mage instances. Read more about Docker Networks here. The following guides detail various methods for creating databases and connecting them to your Mage project. We recommend starting with a docker compose file, as it affords the most flexibility and customizability. You might choose to usedocker run
instead, as it’s a bit simpler.
Guides
PostgreSQL - Docker compose
PostgreSQL - Docker compose
If you’re using Mage in docker compose, you can easily connect a PostgreSQL database to your Mage container. To do so, first define a
.env
file with the following variables:POSTGRES_DB
POSTGRES_USER
POSTGRES_PASSWORD
POSTGRES_HOST
PG_HOST_PORT
docker-compose.yml
file:PostgreSQL - Docker run
PostgreSQL - Docker run
The following steps will create a PostgreSQL database container and connect it to a Mage container.To use a specific schema in the PostgreSQL database, the connection string could contain the schema name as a parameter:
1
Create Docker network
2
Start PostgreSQL Docker container
3
Launch Mage with `MAGE_DATABASE_CONNECTION_URL`
MSSQL - Docker run
MSSQL - Docker run
1
Create Docker network
2
Start MSSQL Docker container
3
Launch Mage with `MAGE_DATABASE_CONNECTION_URL`
DRIVER={ODBC Driver 18 for SQL Server}
: a formatted string with a version number matching that of the SQL serverSERVER=database_server
: the name or IP address of the database serverDATABASE=database
: the name of the databaseUID=user
: the user ID for the databasePWD=password
: the password for the userENCRYPT=yes
: whether to use encryptionTrustServerCertificate=yes
: whether to trust the server certificate