0
0

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 3 years have passed since last update.

dockerコンテナに環境変数を渡す

Posted at

docker run実行時に-eオプションで環境変数が渡せる。
設定情報を渡すのに使用したりする。

$ docker run --help | grep -e "-e"
  -e, --env list                       Set environment variables

確認

$ docker run -it --rm -e HOGE=FUGA -e AAA=BBB centos:centos8 /bin/bash 
[root@45aa4a408e51 /]# echo $HOGE
FUGA
[root@45aa4a408e51 /]# echo $AAA
BBB
[root@45aa4a408e51 /]# 

また、--env-fileを使うことで環境変数が書かれたファイルから環境変数を渡すことができる。

.env_test
HOGE=FUGA
A=B
TEST=TESTdesu
$ docker run --env-file ./.env_test --rm -it centos:centos8 /bin/bash
[root@d9801c8c2542 /]# echo $HOGE
FUGA
[root@d9801c8c2542 /]# echo $A
B
[root@d9801c8c2542 /]# echo $TEST
TESTdesu
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?