【问题标题】:docker build fails on a cloud VMdocker build 在云虚拟机上失败
【发布时间】:2016-08-15 06:22:10
【问题描述】:

我有一个在 Azure VM 中运行的 Ubuntu 16.04 (Xenial)。我已按照说明安装 Docker,一切看起来都很好。

当我触发docker run 时,我需要做的一件事是传递--net=host,它允许我在容器内运行apt-get update 和其他依赖互联网的命令。

当我尝试基于现有的 Ubuntu 映像触发 docker build 时,问题就出现了。它失败了:

这里的问题是没有办法将--net=host 传递给构建命令。我看到 Docker GitHub 上存在一些问题(#20987#10324)但没有明确的解决方案。

有一个 existing answer on Stack Overflow 涵盖了我想要的场景,但这在云虚拟机中不起作用。

对可能发生的事情有什么想法吗?

更新 1:

这是docker version 的输出:

Client:
 Version:      1.12.0
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   8eab29e
 Built:        Thu Jul 28 22:11:10 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.12.0
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   8eab29e
 Built:        Thu Jul 28 22:11:10 2016
 OS/Arch:      linux/amd64

更新 2:

这是docker network ls的输出:

NETWORK ID          NAME                DRIVER              SCOPE
aa69fa066700        bridge              bridge              local               
1bd082a62ab3        host                host                local               
629eacc3b77e        none                null                local   

【问题讨论】:

  • apt-get 仍应使用默认桥接网络工作,除非您的网络需要使用代理服务器或具有阻止 NAT 流量的防火墙规则。如果您尝试使用桥接网络在容器中运行 ping 或 curl 会发生什么?
  • pingcurl 都直接在 VM 上工作。 docker build 仍然失败。
  • 它们在容器中工作吗? VM 使用主机网络,但容器使用桥接网络。
  • 这是诀窍,如上所述 - 当我执行docker run 时,我可以通过--net=host 然后pingapt-getcurl 将起作用。无法将--net=host 传递给docker build,这会导致失败。
  • 我的意思是默认使用桥接网络,这些仍然可以工作。找出这些不起作用的原因可能会帮助您找到解决问题的方法。

标签: azure ubuntu docker cloud containers


【解决方案1】:

另一种方法是尝试让 docker-machine 为您配置虚拟机,看看是否可行。有一个provider for Azure,因此您应该能够在本地 Docker 客户端(Windows 或 Linux)上设置您的订阅 ID,并使用follow the instructions 来获得一个使用 Docker 配置的新 VM,它还将设置您的本地环境变量以进行通信远程使用 Docker VM 实例。设置完成后,在本地运行 docker psdocker run 会像在 VM 上运行命令一样运行命令。示例:

#Name at end should be all lower case or it will fail.
docker-machine create --driver azure --azure-subscription-id <omitted> --azure-image canonical:ubuntuserver:16.04.0-LTS:16.04.201608150 --azure-size Standard_A0 azureubuntu
#Partial output, see docker-machine resource group in Azure portal
Running pre-create checks...
(azureubuntu) Completed machine pre-create checks.
Creating machine...
(azureubuntu) Querying existing resource group.  name="docker-machine"
(azureubuntu) Resource group "docker-machine" already exists.
(azureubuntu) Configuring availability set.  name="docker-machine"
(azureubuntu) Configuring network security group.  location="westus" name="azureubuntu-firewall"
(azureubuntu) Querying if virtual network already exists.  name="docker-machine-vnet" location="westus"
(azureubuntu) Configuring subnet.  vnet="docker-machine-vnet" cidr="192.168.0.0/16" name="docker-machine"
(azureubuntu) Creating public IP address.  name="azureubuntu-ip" static=false
(azureubuntu) Creating network interface.  name="azureubuntu-nic"
(azureubuntu) Creating virtual machine.  osImage="canonical:ubuntuserver:16.04.0-LTS:16.04.201608150" name="azureubuntu" location="westus" size="Standard_A0" username="docker-user"
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with ubuntu(systemd)...
Installing Docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env azureubuntu

#Set environment using PowerShell (or login to the new VM) and see containers on remote host
docker-machine env azureubuntu | Invoke-Expression
docker info
docker network inspect bridge

#Build a local docker project using the remote VM
docker build MyProject
docker images

#To clean up the Azure resources for a machine (you can create multiple, also check docker-machine resource group in Azure portal)
docker-machine rm azureubuntu

我可以说它工作正常。我能够在 Azure VM 上构建一个使用 apt-get 的 debian:wheezy DockerFile,没有任何问题。这应该允许容器使用默认的桥接网络而不是主机网络运行。

【讨论】:

  • 我会尝试这样做,看看它会输出什么结果。我根据虚拟机配置配置了 DNS 设置,所以不确定是什么导致了失败。
【解决方案2】:

根据I can't get Docker containers to access the internet? 使用sudo systemctl restart docker 可能会有所帮助,或者启用net.ipv4.ip_forward = 1disable the firewall

另外,您可能需要在 VM 上的 /etc/resolv.conf 中 update the dns servers

【讨论】:

  • 就像该问题的原始海报一样,所有这些项目都已解决,不幸的是没有任何效果。 --net=host 在我做 docker run 时有效,这太棒了,对我有用。 docker build 失败了。
  • 您看到的问题是您的网桥无法与外界连接,以后可能会出现其他问题。如果您不打算在 docker 中使用桥接网络,您可以尝试使用 docker network rm 将其删除,但网络隔离是人们通常使用 docker 容器的重要原因。因此 --net=host 参数可能不适用于所有 docker 命令。
  • 出于诊断目的,将主帖更新为docker network ls 的输出。
  • 是的......这一切都很普通。问题可能出在 sysctl 或 VM 的 DNS 设置中。我将尝试使用 docker-machine 启动一个 Azure VM,看看它是否在那里工作。
  • 愚蠢的问题,但是您可以通过此 VM 使用所需的协议访问 Internet 上的任何内容吗?我对 Azure 防火墙的体验是,它并不总是像人们想象的那样工作..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-23
  • 2020-06-11
  • 2021-03-06
  • 1970-01-01
  • 2018-12-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多