![](/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.