docker构build在云VM上失败

我有一个在Azure虚拟机内运行的Ubuntu 16.04(Xenial)。 我已经按照说明安装了Docker,所有的东西看起来都不错。

当我触发--net=host docker run时,我需要做的事情之一是传递--net=host ,它允许我在容器中运行apt-get update和其他因特网相关的命令。

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

在这里输入图像说明

这里的问题是,没有办法将--net=host传递给build命令。 我发现在Docker GitHub( #20987 , #10324 )上有问题,但没有明确的解决scheme。

在Stack Overflow上有一个覆盖我想要的场景的现有答案 ,但是这在云VM中不起作用。

有关可能发生什么的任何想法?

更新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 

另一种方法是尝试让docker机为你提供虚拟机,看看是否有效。 有一个Azure的提供者 ,所以你应该能够在本地的Docker客户端(Windows或Linux)上设置你的订阅ID,并按照说明获得一个新的VMconfiguration的Docker,它也将设置你的本地环境variables进行通信与Docker VM实例远程连接。 在运行docker psdocker run setup之后,运行这些命令就好像你在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 

最好的我可以告诉,工作正常。 我能够构build一个debian:wheezy DockerFile,它使用Azure虚拟机上的apt-get,没有任何问题。 这应该允许容器运行使用默认的桥接networking,而不是主机networking。

根据我不能让Docker容器访问互联网? 使用sudo systemctl restart docker可能会有所帮助,或启用net.ipv4.ip_forward = 1或禁用防火墙 。

另外,您可能需要更新 VM上/etc/resolv.conf中的dns服务器