英文:
"docker-compose up" results in "stat main.go: no such file or directory" error
问题
我是你的中文翻译助手,以下是你要翻译的内容:
我对docker-compose
和go
都不太熟悉,所以请多包涵。我在 Stack Overflow 上查看了类似的问题,但它们要么是针对不同版本的 Go,要么是针对 Linux 的。我使用的是 Windows 10,Go 版本是 1.19
。
我正在尝试跟随一个过时的课程,他们使用的是 Mac,所以这可能是导致问题的另一个原因,但是我有一个项目结构和文件,看起来像这样(感兴趣的区域已经用高亮标出):
当我尝试像课程中所说的那样运行 docker-compose up
命令时,我遇到了错误。是什么导致了这个错误,以及我该如何修复它(作为一个新手提问)?
英文:
I'm new to docker-compose
and go
so be kind. I've looked at similar questions to this on SO, but they're either 1) for different versions of Go or 2) for Linux. I'm on Windows 10. Go version is 1.19
I'm trying to follow along with a course which is out of date of course, and they're using a Mac, so that might be another reason why this isn't working, but I have a project structure and files that look like this (highlighted areas of interest):
When I try to run the command docker-compose up
like it says in the course, I get the error. What's causing it and how do I fix it (as a newbie asking)?
答案1
得分: 2
你可以尝试像这样构建并尝试运行二进制文件。这里是有关Docker的文档
以防链接失效:
FROM golang:1.16-alpine
WORKDIR /app
COPY go.mod ./
COPY go.sum ./
RUN go mod download
COPY . ./
RUN go build -o /<你的二进制文件名>
EXPOSE 8080
CMD [ "/<相同的二进制文件名>" ]
英文:
You could try something like this where you build first and then try to run the binary. here is the docker documentation on it
and in case the link breaks:
FROM golang:1.16-alpine
WORKDIR /app
COPY go.mod ./
COPY go.sum ./
RUN go mod download
COPY . ./
RUN go build -o /<your binary name>
EXPOSE 8080
CMD [ "/<same binary name>" ]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论