這是我的 DockerfileFROM golang:1.13 as builderWORKDIR /appCOPY invoke.go ./COPY readproperties.go ./COPY config.properties ./RUN CGO_ENABLED=0 GOOS=linux go build -v -o serverFROM fishtownanalytics/dbt:0.19.0USER rootWORKDIR /dbtCOPY --from=builder /app/server ./COPY script.sh ./COPY jaffle-shop ./ENTRYPOINT ["./server"]當我運行 Docker 鏡像并且 Go 服務器(invoke.go 具有調用 readproperties 函數的主函數)引用 config.properties 時,我收到以下錯誤:2021/04/21 22:27:29 Go: starting server...2021/04/21 22:27:29 open config.properties: no such file or directory如何復制屬性文件?它有對key=value以這種方式構建和運行:docker build -t sample:v1PORT=8080 && docker run -p 9090:${PORT} -e PORT=${PORT} sample:v1所有文件都位于 與 相同的位置。Dockerfile
1 回答

猛跑小豬
TA貢獻1858條經驗 獲得超8個贊
您的屬性文件將復制到“構建器”階段 - 在編譯期間不需要它。相反,它應該被復制到最后階段。
將 Docker 文件更新為:
FROM golang:1.13 as builder
WORKDIR /app
COPY invoke.go ./
COPY readproperties.go ./
#
# REMOVE:
#
# COPY config.properties ./
RUN CGO_ENABLED=0 GOOS=linux go build -v -o server
FROM fishtownanalytics/dbt:0.19.0
USER root
WORKDIR /dbt
COPY --from=builder /app/server ./
COPY script.sh ./
COPY jaffle-shop ./
#
# ADD:
#
COPY config.properties ./
#
# OR: copy it from the builder stage
#
#COPY --from=builder /app/config.properties ./
ENTRYPOINT ["./server"]
- 1 回答
- 0 關注
- 112 瀏覽
添加回答
舉報
0/150
提交
取消