Using an external database on Docker - Amplia
The standard Docker compose file for Amplia includes an internal service for the database (Microsoft SQL Server).
For production environments, there may be concerns about running the database on Docker. If you prefer, follow the steps on this article to use an external database.
Stop the stack:
docker stack rm amplia
Edit the Docker compose file:
nano amplia-stack.yml
Make the following changes:
- Section volumes: remove item sql
- Section services:
- Remove entire service sql
- Service amplia
- On section environment, add the following items:
- SQL_HOST: hostname of the database server
- SQL_PORT (optional): port of the database server (if omitted port 1433 is assumed)
- SQL_DATABASE: name of the database to use
- SQL_USER: username to authenticate on the database server
- Remove section depends_on
- On section environment, add the following items:
The password should be added as the secret amplia_sql_password:
echo 'MyPassword' | docker secret create amplia_sql_password -
Deploy the stack with the new configurations:
docker stack deploy -c amplia-stack.yml amplia
Custom connection string
The method above uses the provided host, database, user and password file to build a connection string with the following format:
Data Source=HOST;Initial Catalog=DATABASE;User ID=USER;Password=PASSWORD
On certain scenarios the connection string might be more complex, for instance if the database is mirrored. On such cases, follow the steps below to use a custom connection string.
Edit the Docker compose file:
nano amplia-stack.yml
Make the following changes:
- Section volumes: remove item sql
- Section secrets: remove item amplia_sql_password
- Section services:
- Remove entire service sql
- Service amplia
- On section secrets, remove item amplia_sql_password
- On section environment, remove all items starting with SQL_
- Remove section depends_on
Edit the Amplia configuration file:
nano amplia.json
Add the ConnectionStrings section to the file, with a single item named DefaultConnection
:
{
"ConnectionStrings": {
"DefaultConnection": "YOUR-CUSTOM-CONNECTION-STRING"
},
"Application": ...
}