2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

docker-compose の .env ファイルとは? コンテナの中で使える環境変数ではなく、あくまで docker-compose の記法で評価されるらしい。( #docker ))

Last updated at Posted at 2019-10-21

.env

MESSAGE=yes

docker-compose.yml

version: '3'
services:
  message:
    image: alpine
    command: "echo ${MESSAGE}"
  display-env:
    image: alpine
    command: env

run

コマンドとして渡したメッセージは表示されるが、環境変数が増えているわけではない。

$ docker-compose run message
yes
$ docker-compose run display-env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=925b3197c65a
TERM=xterm
HOME=/root

.env ファイルよりも docker-compose コマンドに渡す環境変数のほうが強い

$ docker-compose run message
yes

$ MESSAGE=overwritten docker-compose run message
overwritten

ref

Environment variables in Compose | Docker Documentation

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?