简体   繁体   English

Golang docker库映像无法在$ PATH中找到go工具

[英]Golang docker library image cannot find go tool in $PATH

I opened an issue on docker-library/golang#164 , because I think this is a bug. 我在docker-library / golang#164上打开了一个问题,因为我认为这是一个错误。 However, I thought I'd also ask on StackOverflow to see if anyone else (besides project contributors) have encountered this or have any ideas? 但是,我想我也会在StackOverflow上询问是否有其他人(除项目贡献者之外)遇到此问题或有任何想法?

First things first, the version numbers: 首先,版本号是:

$ docker version
Client:
 Version:      17.03.1-ce
 API version:  1.27
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Tue Mar 28 00:40:02 2017
 OS/Arch:      darwin/amd64

Server:
 Version:      17.03.1-ce
 API version:  1.27 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Fri Mar 24 00:00:50 2017
 OS/Arch:      linux/amd64
 Experimental: true

$ docker-compose version
docker-compose version 1.11.2, build dfed245
docker-py version: 2.1.0
CPython version: 2.7.12
OpenSSL version: OpenSSL 1.0.2j  26 Sep 2016

I'm getting the following error: 我收到以下错误:

Cannot start service web: oci runtime error: container_linux.go:247: starting container process caused "exec: \"go\": executable file not found in $PATH"

And this is my Dockerfile : 这是我的Dockerfile

FROM golang:1.8

WORKDIR /go/src/gigem
COPY . /go/src/gigem

RUN go build
RUN go install

CMD ["gigem"]

I'm also using Compose (and I'll include the yml, but the error occurs with/without compose): 我也在使用Compose(并且我将包括yml,但是在有/没有compose的情况下都会发生错误):

version: '3'
services:
  db:
    image: postgres
    volumes:
      - ./data:/var/lib/postgresql/data
  web:
    build: .
    volumes:
      - .:/go/src/gigem
    ports:
      - "3000:3000"
    depends_on:
      - db

And all that's in my Go program is: 在我的Go程序中,所有内容是:

package main

import (
  "fmt"
  "net/http"
)

func main() {
  http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello Docker!")
  })

  fmt.Println("Running!")
  fmt.Println(http.ListenAndServe("0.0.0.0:3000", nil))
}

I'm not quite sure why go is not being found in the $PATH . 我不太确定为什么在$PATH找不到go。

I recently tested your Dockerfile and main.go, and I did not find any errors. 我最近测试了您的Dockerfile和main.go,但没有发现任何错误。

I think you should try to pull golang: 1.8 again using docker build --pull . 我认为您应该尝试使用docker build --pull .再次拉出golang: 1.8 docker build --pull .

I modified your Dockerfile adding two new lines to debug the image, try: 我修改了您的Dockerfile,添加了两行来调试映像,请尝试:

FROM golang: 1.8
    
WORKDIR / go / src / gigem
COPY. / Go / src / gigem

RUN echo $ PATH
RUN which go
RUN go build
RUN go install

CMD ["gigem"]

Echo $ PATH and which go will show you if the binary go is inside the PATH Echo $ PATH ,如果二进制文件goEcho $ PATHwhich go会显示给您

From the comments, I tested this code myself without error (admittedly on 17.06-rc2 but the behavior shouldn't change). 从注释中,我自己测试了此代码,没有错误(公认的是在17.06-rc2上,但是行为不应更改)。 Given that a restart solved this, there appears to have been some corruption inside of docker that needed a bounce to correct (while rare, it wouldn't be the first time I've seen this). 鉴于重启解决了这个问题,码头工人内部似乎出现了一些损坏,需要反弹来纠正(虽然很少见,但这不是我第一次看到它)。 For others encountering problems in the future, I like to try the following in order: 对于将来遇到问题的其他人,我喜欢按以下顺序尝试:

  1. Pull fresh images and/or rebuild without caching for any issues with the layers 提取新图像和/或重建而不缓存层的任何问题
  2. Restart docker for possible corruption inside the daemon 重新启动docker,以防守护程序内部损坏
  3. Restart the entire host for runtime configuration issues that persist outside of the docker daemon 重新启动整个主机,以解决在docker守护程序之外仍然存在的运行时配置问题
  4. With dockerd stopped, wipe /var/lib/docker which will destroy all containers, images, and volumes (so backup first) and start clean 在dockerd停止的情况下,擦除/var/lib/docker docker,这将销毁所有容器,图像和卷(因此请先备份)并开始清理

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

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