如何将环境变量传递给docker-compose up [英] How to pass environment variable to docker-compose up
本文介绍了如何将环境变量传递给docker-compose up的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试运行一个容器。我已经将映像上传到私有Docker注册表。我想编写一个撰写文件来下载和部署映像。但是我想通过docker-compose run命令将TAG名称作为变量传递。我的撰写文件如下所示。如何作为docker-compose up命令的一部分传递KB_DB_TAG_VERSION的值?
I am trying to run a container. I already have the image uploaded to private Docker registry. I want to write a compose file to download and deploy the image. But I want to pass the TAG name as a variable from the docker-compose run command.My compose file looks like below. How can I pass the value for KB_DB_TAG_VERSION as part of docker-compose up command?
version: '3'
services:
db:
#build: k-db
user: "1000:50"
volumes:
- /data/mysql:/var/lib/mysql
container_name: k-db
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
image: XX:$KB_DB_TAG_VERSION
image: k-db
ports:
- "3307:3306"
推荐答案
两个选项:
- Create the .env file as already suggested in another answer.
Prepend
KEY=VALUE
pair(s) to yourdocker-compose
command, e.g:
KB_DB_TAG_VERSION=kb-1.3.20-v1.0.0 docker-compose up
早些时候将其导出na脚本也应正常工作,例如:
Exporting it earlier in a script should also work, e.g.:
export KB_DB_TAG_VERSION=kb-1.3.20-v1.0.0
docker-compose up
这篇关于如何将环境变量传递给docker-compose up的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文