Connect to a Database
Connecting means giving your app or computer the host, port, username, password, and database name needed to talk to the database.
From an app
Link the database to a project, then redeploy:
dock db link production my-app
dock deployDockHosting injects database environment variables into the app.
What is linking? Linking means DockHosting saves the relationship between one app project and one database. On the next deploy, the app receives database connection variables such as host, port, username, password, and connection URL.
Linking is not magic code Your app still needs to read the environment variable and use it in your database client. Linking only provides the credentials.
From your machine
Use the public connection string only after public access is enabled and your IP is allowed by the firewall.
dock db connection productionInternal vs public host
| Host type | Use it for |
|---|---|
| Internal host | Apps running on DockHosting |
| Public host | Local clients, external tools, temporary admin access |
Common app examples
Node.js usually reads a variable like:
const databaseUrl = process.env.DATABASE_URL;Python usually reads it like:
import os
database_url = os.environ["DATABASE_URL"]Laravel usually uses .env-style variables. After linking and redeploying,
check the app logs if the framework still cannot find the database.