![](/img/trans.png)
[英]how to run docker container with external application properties file?
[英]Docker Container - Missing properties file
這是我的 Dockerfile
FROM golang:1.13 as builder
WORKDIR /app
COPY invoke.go ./
COPY readproperties.go ./
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 ./
ENTRYPOINT ["./server"]
當我運行 Docker 圖像和 Go 服務器(invoke.go 具有調用 readproperties 函數的 main)時,我得到以下錯誤:
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:v1
PORT=8080 && docker run -p 9090:${PORT} -e PORT=${PORT} sample:v1
所有文件都與Dockerfile
位於同一位置。
您的屬性文件被復制到“構建器”階段 - 在編譯期間不需要它。 相反,它應該被復制到最后階段。
將您的 Dockerfile 更新為:
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"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.