简体   繁体   English

构建 Dockerfile 的问题

[英]Issues with building Dockerfile

RUN mkdir /app
WORKDIR /app

# We want to populate the module cache based on the go.{mod,sum} files.
COPY go.mod .
COPY go.sum .

RUN go mod download

COPY . .

# Build the Go app
RUN go build -o ./out/go-sample-app .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o main app/server.go

# This container exposes port 8080 to the outside world
EXPOSE 8080

# Run the binary program produced by `go install`
CMD ["go", "run, "server.go"]

The error which I am getting is this.我得到的错误是这个。 So I've been trying to write a Dockerfile for the first time for my Golang App and this is the issue I am running into.所以我第一次尝试为我的 Golang 应用程序编写 Dockerfile,这就是我遇到的问题。

time="2020-10-06T07:03:55+05:30" level=error msg="Can't add file \\\\?\\D:\\0 NAT IT\\DumGo\\.git\\hooks\\update.sample to tar: io: read/write on closed pipe"
time="2020-10-06T07:03:55+05:30" level=error msg="Can't close tar writer: io: read/write on closed pipe"
error during connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=zuyf430dft91rrte7rvtw9kjg&shmsize=0&target=&ulimits=null&version=1: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.

The file structure is like文件结构就像

~DumGo
   /graph
Dockerfile
go.mod
go.sum
server.go

@divan_cyph make sure you have docker running. @divan_cyph 确保您正在运行 docker。 You can check by executing docker info from your cli.您可以通过从 cli 执行docker info来检查。

Side note, you can save a couple of lines by just adding your COPY . .旁注,您只需添加COPY . .即可节省几行COPY . . COPY . . above the go mod download call, and removing both COPY go.mod .go mod download调用上方,并删除COPY go.mod . and COPY go.sum .COPY go.sum .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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