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

docker-composeの変数&複数定義を使用する

Last updated at Posted at 2021-04-04

■docker-compose.yml で変数を使用

docker-compose.yml
version: "3.7"

x-var: &NAME
  "app-test"

services:
  app:
    container_name: *NAME

■docker-compose.yml で環境変数を使用

docker-compose.yml
version: "3.7"

services:
  app:
    # docker-composeを呼び出す前に「NAME」を設定しておく
    container_name: ${NAME}

※ 「app:」の個所を「${NAME}:」のように定義は出来ません

■複数のdocker-compose.yml の設定をマージして使用

※後からコンテナーを増やしていく際、共通の定義があるなら便利です

docker-compose-base.yml
version: '3.7'

services:
  app:
    container_name: app-test
    volumes:
      - /common/:/common/
    networks:
      - custom-network
docker-compose-app.yml
version: '3.7'

services:
  app:
    build:
      context: .
      args:
        TEST_1: 123
docker-compose -f docker-compose-base.yml -f docker-compose-app.yml up -d --build
0
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
0
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?