Docker:无法解析主机:github.com-进行获取。

在运行Dockerfile时,我需要获取依赖项。 这是使用 go get ./...</ code>完成的。</ p>

但是,当执行 docker build -t test </ </ code>时,它会挂在 去获取命令。 </ p>

这是错误消息</ h3>


exec go get -v -d </ p>

github.com/gorilla/mux(下载)
cd。; git clone https://github.com/gorilla/mux /go/src/github.com/gorilla / mux克隆到
'/go/src/github.com/gorilla/mux'...致命:无法访问
' https://github.com/gorilla/mux/ ':无法解析主机:github.com
包github.com/gorilla/mux:退出状态128 </ p> \ n </ blockquote>

这是dockerfile </ h3>

  FROM golang 

#在容器内创建一个目录来存储我们所有的应用程序,然后 使其成为工作目录。
RUN mkdir -p / go / src / example-app
WORKDIR / go / src / example-app

#将example-app目录(Dockerfile所在的目录)复制到容器中。

COPY。 / go / src / example-app

#将所有必需的第三方依赖项下载并安装到容器中。
RUN go-wrapper下载
RUN go-wrapper安装
RUN go get ./...

#在容器内设置PORT环境变量
ENV PORT 8080

#将端口8080暴露给主机,以便我们可以访问我们的应用程序
EXPOSE 8080

#现在告诉Docker容器启动时运行什么命令\ nCMD [“ go-wrapper”,“ run”]
</ code> </ pre>
</ div>

展开原文

原文

When running my Dockerfile I need to grab dependencies. This is done using go get ./....

However when doing docker build -t test . it hangs at the go get command.

here is the error message

exec go get -v -d

github.com/gorilla/mux (download) cd .; git clone https://github.com/gorilla/mux /go/src/github.com/gorilla/mux Cloning into '/go/src/github.com/gorilla/mux'... fatal: unable to access 'https://github.com/gorilla/mux/': Could not resolve host: github.com package github.com/gorilla/mux: exit status 128

here is the dockerfile

FROM golang

# Create a directory inside the container to store all our application and then make it the working directory.
RUN mkdir -p /go/src/example-app
WORKDIR /go/src/example-app

# Copy the example-app directory (where the Dockerfile lives) into the container.
COPY . /go/src/example-app

# Download and install any required third party dependencies into the container.
RUN go-wrapper download
RUN go-wrapper install
RUN go get ./...

# Set the PORT environment variable inside the container
ENV PORT 8080

# Expose port 8080 to the host so we can access our application
EXPOSE 8080

# Now tell Docker what command to run when the container starts
CMD ["go-wrapper", "run"]

1个回答



我假设您正在另一台计算机上通过ssh进行此操作。 检查您的 / etc / network / interfaces </ code>中是否有dns服务器。 它应该看起来像这样:</ p>

  iface eth0 inet静态
地址192.168.2.9
网关192.168.2.1
网络掩码255.255.255.0
广播192.168.2.255 \ n dns-nameservers 192.168.2.1 8.8.4.4
</ code> </ pre>

“始终”起作用的DNS服务器是 8.8.8.8 </ code>和 8.8 .4.4 </ code>,均由Google提供。 如果那不能解决您的问题,则应检查Internet连接是否有其他错误配置,但请先尝试一下。</ p>
</ div>

展开原文

原文

I assume you're doing that via ssh on another machine. Check if it has a dns server in your /etc/network/interfaces. It should look somehow like this:

iface eth0 inet static
    address 192.168.2.9
    gateway 192.168.2.1
    netmask 255.255.255.0
    broadcast 192.168.2.255
    dns-nameservers 192.168.2.1 8.8.4.4

DNS servers that "always" work are 8.8.8.8 and 8.8.4.4, both provided by Google. If that doesn't resolve your problem, you should check your internet connection for other misconfigurations, but first try this.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐