124
98

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

docker-compose.ymlでDockerfileを指定したい

Last updated at Posted at 2018-10-23

概要

docker-compose.yml で複数コンテナの定義をする際に、Dockerfileは別にしたい!と調べてたらできたのでメモ。

手順

> mkdir 任意のディレクトリ
> cd 任意のディレクトリ
> touch docker-compose.yml
> touch Dockerfile1
> touch Dockerfile2

build.dockerfile で指定ができるみたいです。

docker-compose.yml
version: '3'

services:
  container1:
    build:
      context: .
      dockerfile: Dockerfile1
  container2:
    build: 
      context: .
      dockerfile: Dockerfile2
  container3:
    build: .
Dockerfile1
FROM python:3.6
Dockerfile2
FROM node:latest

コンテナを起動してみます。

> docker-compose up --build

Creating network "任意のディレクトリ_default" with the default driver
Building container1
Step 1/1 : FROM python:3.6
 ---> 4f13b7f2138e
Successfully built 4f13b7f2138e
Successfully tagged 任意のディレクトリ_container1:latest
Building container2
Step 1/1 : FROM node:latest
 ---> b064644cf368
Successfully built b064644cf368
Successfully tagged 任意のディレクトリ_container2:latest
Building container3
Step 1/1 : FROM python:3.6
 ---> 4f13b7f2138e
Successfully built 4f13b7f2138e
Successfully tagged 任意のディレクトリ_container3:latest
Creating 任意のディレクトリ_container3_1 ... done
Creating 任意のディレクトリ_container2_1 ... done
Creating 任意のディレクトリ_container1_1 ... done
Attaching to 任意のディレクトリ_container1_1, 任意のディレクトリ_container2_1, 任意のディレクトリ_container3_1
任意のディレクトリ_container1_1 exited with code 0
任意のディレクトリ_container2_1 exited with code 0
任意のディレクトリ_container3_1 exited with code 0

やったぜ。

参考

docker-compose コマンドまとめ
https://qiita.com/wasanx25/items/d47caf37b79e855af95f

124
98
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
124
98

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?