Answer the question
In order to leave comments, you need to log in
How to use one database for multiple sites running on Docker?
Several websites are running on the server. Autodeploy via gitlab is configured as follows:
1. After the build, the image is uploaded to the server
2. Docker-compose.yml is loaded into the project folder (which contains the .env file, mount folders, etc.) something like this (deleted what off topic):
version: '3.2'
services:
web:
image: project-name
environment:
- DB_HOST=${DB_HOST:-db}
- DB_DATABASE=${DB_DATABASE:-project-name}
- DB_USER=${DB_USER:-project-name}
- DB_PASSWORD=${DB_PASSWORD:-password}
db:
image: mariadb:10.3.8
deploy:
resources:
limits:
memory: ${LIMIT_DB_MEM:-80M}
environment:
- MYSQL_RANDOM_ROOT_PASSWORD=yes
- MYSQL_DATABASE=${DB_DATABASE:-project-name}
- MYSQL_USER=${DB_USER:-project-name}
- MYSQL_PASSWORD=${DB_PASSWORD:-password}
docker-compose config > docker-stack.yml
docker stack deploy -c docker-stack.yml project-name
docker-compose up --build
and everything rises by itself, no fuss with the database, network, etc.Answer the question
In order to leave comments, you need to log in
My question is: can the current configuration be reworked so that when certain variables in .env (for example, when DB_HOST is not equal to db), the db service does not start?
networks:
default:
external:
name: db_default
...
services:
web:
image: project-name
networks:
- default
- db_default
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question