[英]How to deploy multiple databases with one docker-compose.yml using env variables?
This is my docker-compose.yml
:这是我的docker-compose.yml
:
version: "3"
services:
db:
container_name: "container_${DB_NAME}"
image: mysql:5
restart: always
environment:
MYSQL_DATABASE: "${DB_NAME}"
MYSQL_ROOT_PASSWORD: "${DB_PASSWORD}"
ports:
- "${DB_PORT}:3306"
And this is my .env.development
(one of my.env files):这是我的.env.development
(my.env 文件之一):
PORT=3000
DB_HOST=localhost
DB_PORT=3306
DB_NAME=db_dev
DB_USERNAME=root
DB_PASSWORD=root
I use to deploy db service with docker-compose --env-file.env.development up
and it works perfectly.我使用docker-compose --env-file.env.development up
部署数据库服务,它运行良好。
However, if I want to deploy another db service at the same time with another.env file (with for example docker-compose --env-file.env.production up
), the first one is stopped and this is the message I get:但是,如果我想同时部署另一个 db 服务和另一个 .env 文件(例如docker-compose --env-file.env.production up
),第一个停止,这是我得到的消息:
Recreating container_db_dev ... done
Attaching to container_db_prod
So my question is, can I use one docker-compose.yml like this one and deploy multiple database services depending on.env given file?所以我的问题是,我可以像这样使用一个 docker-compose.yml 并根据给定的 .env 文件部署多个数据库服务吗?
You can use the -p
command to specific your compose stack name.您可以使用-p
命令指定您的组合堆栈名称。
docker-compose -p "new_stack" --env-file.env.production up
The answer I get from stack name with docker-compose我从堆栈名称中得到的答案是 docker-compose
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.