Mixing ENV variables with and without assignments in docker compose yaml for Gitlab CI - Stack Overflow

In trying to set up a database container via compose, I ran into issues with credential management. I w

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

There 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}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745620770a4636500.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信