docker build在云虚拟机上失败

时间:2016-08-15 06:22:11

标签: azure ubuntu docker cloud containers

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

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

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

enter image description here

这里的问题是无法将--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   

2 个答案:

答案 0 :(得分:1)

另一种方法是尝试让docker-machine为您配置VM并查看是否有效。有provider for Azure,因此您应该能够在本地Docker客户端(Windows或Linux)和follow the instructions上设置订阅ID以获取使用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

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

答案 1 :(得分:0)

根据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