我刚刚开始使用 Golang 并尝试使用 docker-compose 构建 go gin。这是我的 Dockerfile
FROM golang:1.18
WORKDIR /docker-go
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
# COPY all file go ./
COPY ./app/main.go ./
COPY . /docker-go
# To initialize a project with go module, create go.mod
RUN go mod init shipping-go
# Add missing and/or remove unused modules
RUN go mod tidy
# This will bring all the vendors to your projects /vendor directory so that
# you don't need to get the modules again if working from another machine on this project.
RUN go mod vendor
RUN go mod download && go mod verify
COPY . .
RUN go build -v -o /docker-go/app .
RUN chmod +x /docker-go
USER root
和我的 docker-compose
version: "3.7"
services:
go-web:
build:
context: ./
dockerfile: Dockerfile
restart: 'no'
working_dir: /docker-go
ports:
- "8080:8080"
entrypoint: ["./start.sh"]
volumes:
- ./:/docker-go
当我用命令检查日志容器时出现错误
docker logs learn-docker-go_go-web_1
/docker-go
go: cannot find main module, but found .git/config in /docker-go
to create a module there, run:
go mod init
/docker-go
它似乎找不到模块文件,但我已经安装在 Dockerfile 中。对于详细信息,我将代码推送到我的存储库中 https://github.com/duyanh1904/learn-docker-go
不负相思意
相关分类