Multiple images, one Dockerfile

前端 未结 2 862
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:11

    You can use a docker-compose file using the target option:

    version: '3.4'
    services:
      img1:
        build:
          context: .
          target: img1
      img2:
        build:
          context: .
          target: img2
    

    using your Dockerfile with the following content:

    FROM alpine as img1
    COPY file1.txt .
    
    FROM alpine as img2
    COPY file2.txt .
    

提交回复
热议问题