LoginSignup
6
4

More than 1 year has passed since last update.

#docker - Dockerfile + docker-compose で development / production などの環境を切り替える (まるちすてーじびるど!)

Last updated at Posted at 2019-10-18
  • Dockerfile の FROM AS で、てきとう名前をつけてマルチステージビルドする。作成したイメージを元に別のイメージを作成する。
  • AS で名前をつけたイメージに対して docker-compose.yml で target 指定する。

って感じで実現できるっぽい。

本番と開発緩急で別の docker-compose.yml を使う感じかな。

FROM python:3.6 as base
RUN apt-get update && apt-get upgrade -y
RUN pip install pipenv pip
COPY Pipfile ./
# some more common configuration...

FROM base as dev
RUN pipenv install --system --skip-lock --dev
ENV FLASK_ENV development
ENV FLASK_DEBUG 1

FROM base as prod
RUN pipenv install --system --skip-lock
ENV FLASK_ENV production
Then you can build one stage or another using the --target syntax to build, or a compose file like:
# docker-compose.yml
version: '3.4'
services:
  webapp:
    build:
      context: ./dir
      dockerfile: Dockerfile
      target: prod

Google Calendar - October 2019

Use multi-stage builds | Docker Documentation

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

6
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
6
4