っぽいのだけど、docker-compose.yml
に書くことはできる
利用方法
AWS_ACCESS_KEY_ID: "${AWS_ACCESS_KEY_ID}"
のように書く- ローカルの環境変数を定義しておく
1 |
<span class="nb">export </span><span class="nv">AWS_ACCESS_KEY_ID</span><span class="o">=</span>AAA |
書き方
docker-compose.yml
1 2 3 4 5 6 7 8 9 10 11 12 |
<span class="na">version</span><span class="pi">:</span> <span class="s1">'</span><span class="s">3'</span> <span class="c1"># composeファイルのバーション指定 </span> <span class="na">services</span><span class="pi">:</span> <span class="na">server</span><span class="pi">:</span> <span class="c1"># service名</span> <span class="na">build</span><span class="pi">:</span> <span class="s">./server/</span> <span class="c1"># ビルドに使用するDockerfileがあるディレクトリ指定</span> <span class="na">environment</span><span class="pi">:</span> <span class="na">AWS_ACCESS_KEY_ID</span><span class="pi">:</span> <span class="s2">"</span><span class="s">${AWS_ACCESS_KEY_ID}"</span> <span class="na">AWS_SECRET_ACCESS_KEY</span><span class="pi">:</span> <span class="s2">"</span><span class="s">${AWS_SECRET_ACCESS_KEY}"</span> <span class="na">ports</span><span class="pi">:</span> <span class="pi">-</span> <span class="s2">"</span><span class="s">8080:8080"</span> <span class="na">tty</span><span class="pi">:</span> <span class="no">true</span> <span class="c1"># コンテナの起動永続化</span> <span class="na">volumes</span><span class="pi">:</span> <span class="pi">-</span> <span class="s">.:/go/src/work</span> <span class="c1"># マウントディレクトリ指定</span> |
確認
1 2 |
yuta:~ $ docker exec -it a9f8b66d9a6f echo $AWS_ACCESS_KEY_ID AAA |