简体   繁体   English

Docker 容器 - 缺少属性文件

[英]Docker Container - Missing properties file

This is my Dockerfile这是我的 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"]

When I run the Docker image and the Go server (invoke.go has the main which calls readproperties function) references the config.properties, I get the following error:当我运行 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

How do I copy the properties file?如何复制属性文件?

It has key=value pairs它有key=value

Building and running this way:以这种方式构建和运行:

docker build -t sample:v1
PORT=8080 && docker run -p 9090:${PORT} -e PORT=${PORT} sample:v1

All the files are in the same location as the Dockerfile .所有文件都与Dockerfile位于同一位置。

Your properties file is copied to the "builder" stage - where it is not needed during compilation.您的属性文件被复制到“构建器”阶段 - 在编译期间不需要它。 Instead it should be copied to the final stage.相反,它应该被复制到最后阶段。

Update your Dockerfile to:将您的 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM