7
4

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】.envの環境変数をDockerfileで使用する

Posted at

.env

.env
SAMPLE_ENV=example

docker-compose.yml

.envファイルに記述した環境変数をargsに記述します。

docker-compose.yml

version: '3.9'
services:

  ・・・

  api:
    build:
      context: .
      dockerfile: ./docker/api/Dockerfile
      args:
        - SAMPLE_ENV=${SAMPLE_ENV}

  ・・・

Dockerfile

ARGdocker-compose.ymlargsに記述した環境変数を取得します。

Dockerfile
ARG SAMPLE_ENV

RUN echo ${SAMPLE_ENV}
7
4
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
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?