使用您的 docker 镜像构建 golang

时间:2021-04-13 08:21:01

标签: docker go jenkins

大家好。我正在使用我们的 docker 镜像构建 go 微服务。为了减少构建时间,请控制图像。

我希望在从 docker hub 下载 golang 镜像后,将其上传到我们的注册表并在我们微服务的所有 dockerfile 中使用它。

当我开始构建 go mircoservice 时,在安装阶段 go 给了我一个错误:

11:04:16 [91m / bin / sh: go: not found
11:04:16 [0mThe command '/ bin / sh -c go install -mod vendor' returned a non-zero code: 127

我尝试在容器中安装 go,为 go 编写 $ PATH,但没有任何帮助。然后我被告知这张图片已经包含 go。

以下是完整的构建步骤:

11:04:15 Step 1/7 : FROM 192.168.0.8:5000/golang
11:04:15  ---> 49f356fa4513
11:04:15 Step 2/7 : EXPOSE 80
11:04:15  ---> Using cache
11:04:15  ---> 6e0c49e600e6
11:04:15 Step 3/7 : WORKDIR /go/src/autocomplete-trains
11:04:15  ---> Using cache
11:04:15  ---> 41cccfb1ed82
11:04:15 Step 4/7 : COPY . .
11:04:15  ---> 1a44653382a8
11:04:15 Step 5/7 : RUN chmod +x ./start.sh
11:04:15  ---> Running in c13b5cfbfd0b
11:04:16 Removing intermediate container c13b5cfbfd0b
11:04:16  ---> ab03d13e5984
11:04:16 Step 6/7 : RUN go install -mod vendor
11:04:16  ---> Running in b3727493f938
11:04:16 [91m/bin/sh: go: not found
11:04:16 [0mThe command '/bin/sh -c go install -mod vendor' returned a non-zero code: 127
11:04:17 Build step 'Execute shell' marked build as failure

Dockerfile:

FROM 192.168.0.8:5000/golang
    
EXPOSE 80
    
WORKDIR /go/src/autocomplete-trains
COPY . .
RUN chmod +x ./start.sh
    
RUN go install -mod vendor
    
ENTRYPOINT ./script.sh

注意:如果将 FROM 192.168.0.8:5000/golang:1.15.5-alpine 更改为 FROM golang,则一切正常(但我们不希望依赖 dockerhub,因此这不是一个可行的解决方案)。< /p>

用于将图像推送到我们的存储库的过程是:

sudo docker pull golang
sudo docker tag golang:latest 192.168.0.8:5000/golang:1.15.5-alpine
sudo docker push 192.168.0.8:5000/golang:1.15.5-alpine

0 个答案:

没有答案