admin管理员组文章数量:1434921
In trying to set up a database container via compose, I ran into issues with credential management. I wanted to be able to use Gitlab secrets/variables to set the db password, etc. and stumpled upon ENV variables without assignments, ie.
gitlab-ci:
MARIADB_ROOT_PASSWORD=$MARIA_ROOT_PASS MARIADB_USER='root' docker compose up --build
with a compose file like this:
environment:
MARIADB_ROOT_PASSWORD
MARIADB_USER
...
This worked if the only ENV vars are those without assignment, but it apparently breaks as soon as you combine it with things like
MARIADB_ROOT_PASSWORD
MARIADB_USER
CUDA_DEVICE_ORDER: "PCI_BUS_ID"
CUDA_VISIBLE_DEVICES: ${CUDA_DEVICES:-'0, 1, 2, 3'}
Is there a way to have both types of ENVs in the same compose file, or do you recommend another way of encorporating CI vars into the build pipeline? Note that i'd like to avoid a .env file on the host server.
In trying to set up a database container via compose, I ran into issues with credential management. I wanted to be able to use Gitlab secrets/variables to set the db password, etc. and stumpled upon ENV variables without assignments, ie.
gitlab-ci:
MARIADB_ROOT_PASSWORD=$MARIA_ROOT_PASS MARIADB_USER='root' docker compose up --build
with a compose file like this:
environment:
MARIADB_ROOT_PASSWORD
MARIADB_USER
...
This worked if the only ENV vars are those without assignment, but it apparently breaks as soon as you combine it with things like
MARIADB_ROOT_PASSWORD
MARIADB_USER
CUDA_DEVICE_ORDER: "PCI_BUS_ID"
CUDA_VISIBLE_DEVICES: ${CUDA_DEVICES:-'0, 1, 2, 3'}
Is there a way to have both types of ENVs in the same compose file, or do you recommend another way of encorporating CI vars into the build pipeline? Note that i'd like to avoid a .env file on the host server.
Share Improve this question asked Nov 18, 2024 at 11:38 LukasIAOLukasIAO 32 bronze badges1 Answer
Reset to default 1There are two syntaxes for environment:
, and both support mixing values defined in the YAML file and values passed through from the host.
environment:
can be a YAML map, with a series of KEY: value
. If you omit a value
half then Compose will pass through a value from the host.
environment:
MARIADB_ROOT_PASSWORD: # <-- note colon at the end, no value
MARIADB_USER:
CUDA_DEVICE_ORDER: "PCI_BUS_ID"
CUDA_VISIBLE_DEVICES: ${CUDA_DEVICES:-0, 1, 2, 3}
You can also set environment:
to a YAML list (typically one value to a line with -
at the start of the line) of KEY=value
strings. In this syntax, just setting KEY
without an =value
half passes through the value.
environment:
- MARIADB_ROOT_PASSWORD # <-- just the variable name
- MARIADB_USER
- CUDA_DEVICE_ORDER=PCI_BUS_ID # quotes will not be removed mid-string
- CUDA_VISIBLE_DEVICES=${CUDA_DEVICES:-0, 1, 2, 3}
本文标签: Mixing ENV variables with and without assignments in docker compose yaml for Gitlab CIStack Overflow
版权声明:本文标题:Mixing ENV variables with and without assignments in docker compose yaml for Gitlab CI - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745620770a2666665.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论