我的 Dockerfile 详细信息是:
# Use the official Go image as the base image
FROM golang:1.22.0
# Set destination for COPY
WORKDIR /app
COPY go.mod /app/go.mod
COPY go.sum /app/go.sum
# Download Go modules
RUN go mod download
COPY ./.env /app/.env
COPY ./config/config.json /app/config.json
COPY ./src/* /app
# Build the Go application
RUN CGO_ENABLED=0 GOOS=linux go build -o app
EXPOSE 8080
# Set the entry point for the container
CMD ["/app"]
当我跑步时
docker build - < DockerFile
输出
=> 错误 [3/9] 复制 go.mod /app/go.mod 0.0s
=> 错误 [4/9] 复制 go.sum /app/go.sum 0.0s
=> 缓存 [5/9] RUN go mod 下载 0.0s
=> 错误 [6/9] 复制 ./.env /app/.env 0.0s
=> 错误 [7/9] 复制 ./config/config.json /app/config.json 0.0s
[3/9] 复制 go.mod /app/go.mod:
[4/9] 复制 go.sum /app/go.sum:
[6/9] 复制./.env /app/.env:
无法计算缓存键:“/.env”未找到:未找到
我的目录中有 go.mod 和 go.sum 文件。
从 docker build 官方文档寻找答案 在此输入链接描述
docker build - < Dockerfile
此示例从 STDIN 读取 Dockerfile,无需上下文。由于缺少上下文,该命令不会将任何本地目录的内容发送到 Docker 守护程序。由于没有上下文,Dockerfile ADD 仅在引用远程 URL 时才有效。