gpt4 book ai didi

docker - 跨容器重用配置

转载 作者:行者123 更新时间:2023-12-02 19:55:16 26 4
gpt4 key购买 nike

将配置传递并重新用于Docker容器的行业惯例是什么,有些配置是常见的,而有些则具有自定义值。例如。

注意,产品容器具有自定义配置参数。 My_CUSTOM_CONFIG

customer:
image: node
build:
context: ./Customer
dockerfile: Dockerfile
environment:
DATABASE_HOST: database
DATABASE_NAME: MyDB
DATABASE_USER: myusername
DATABASE_PASSWORD: mypassword
SERVICE_PORT: 80
depends_on:
- database

product:
image: node
container_name: product
restart: on-failure
build:
context: ./Product
dockerfile: Dockerfile
environment:
DATABASE_HOST: database
DATABASE_NAME: MyDB
DATABASE_USER: myusername
DATABASE_PASSWORD: mypassword
SERVICE_PORT: 80
My_CUSTOM_CONFIG: secret
depends_on:
- consul
- database

enter image description here

最佳答案

看看 env_file :

Add environment variables from a file. Can be a single value or a list.



将其放入 .env中:
DATABASE_HOST=database
DATABASE_NAME=MyDB
DATABASE_USER=myusername
DATABASE_PASSWORD=mypassword
SERVICE_PORT=80

然后在 docker-compose.yml中使用它
customer:
image: node
build:
context: ./Customer
dockerfile: Dockerfile
env_file: .env
depends_on:
- database

product:
image: node
container_name: product
restart: on-failure
build:
context: ./Product
dockerfile: Dockerfile
env_file: .env
environment:
My_CUSTOM_CONFIG: secret
depends_on:
- consul
- database

关于docker - 跨容器重用配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58418417/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com