Docker容器-缺少属性文件
这是我的文件Docker容器-缺少属性文件,docker,go,dockerfile,Docker,Go,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 /
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)引用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:v1
PORT=8080 && docker run -p 9090:${PORT} -e PORT=${PORT} sample:v1
所有文件都与Dockerfile位于同一位置。您的属性文件将复制到“builder”阶段,在编译过程中不需要它。相反,它应该复制到最后阶段 将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"]
您是如何构建映像和启动容器的?您能显示尝试读取属性文件的代码吗?@DavidMaze我已经添加了详细信息。这是您的完整Dockerfile吗?如果不是,您是否正在使用多阶段构建?@colm.anseo我已经添加了整个Dockerfile。