Multiple images, one Dockerfile

前端 未结 2 860
Happy的楠姐
Happy的楠姐 2020-12-16 00:28

How to create two images in one Dockerfile, they only copy different files.

Shouldn\'t this produce two images img1 & img2, ins

2条回答
  •  無奈伤痛
    2020-12-16 01:07

    You can build multiple images from one Docker file by running docker build for each build stage name want to pick out of the Dockerfile (FROM alpine as name).

    By default docker builds the image from the last command in the Dockerfile, however you can target the build to an intermediate layer. Extending from the example Dockerfile in the question, one can:

    docker build -t image1 --target img1 .
    

    ref: https://docs.docker.com/engine/reference/commandline/build/#specifying-target-build-stage---target

提交回复
热议问题