doolo00026 2019-05-13 12:37
浏览 148


I have 2 Dockerfile, 1 for dev, and 1 for prod:


FROM golang AS builder
WORKDIR /go/src/
COPY . .
RUN go build -o ./release/api .

FROM scratch
COPY --from=builder /go/src/ .
CMD ["./api"]

and DEV:

FROM golang
WORKDIR /go/src/
COPY . .
RUN go build -o ./release/api .
CMD ["./release/api"]

I would like to merge those two into a single one, as maintaining 2 Dockerfile is a bad practice

The main difference is that in dev, I work on golang image, which is practical, and in prod, I work with scratch image, which reduce a lot the size of my binary.

It seems that I can use multiple stages in a Dockerfile, and specify stage name at build time:

docker build . --target=builder

But If I do this, I don't know how to conditionnaly run my app in the first stage = [ If I am in dev, run the app in the first stage, otherwise, run the app in the second stage]

How should I do it ?

  • 写回答




      • ¥20 怎么将vs中的程序同步到sql中的表中
      • ¥15 用flask框架接收前端上传的文本文件后怎么读取该文件
      • ¥15 有没有嵌入式ubuntu的朋友
      • ¥50 diddler Burp Suite
      • ¥20 关于UE5.1的问题,求专家解答!
      • ¥30 关于#爬虫#的问题:百度为您找到相关结果约100,000,000个 但只展现70页 有没有可能提取出来全部的搜索结果
      • ¥40 IIS部署API,弄了几天没弄出来,希望带佬远程帮我弄一下,有偿
      • ¥15 关于#c##的问题:winform中利用delegate更新ui的顺序错误
      • ¥15 有没有985信息安全专业的同学说一下你们都学什么。。
      • ¥15 qt5.6.1读取oracle8中文数据乱码