通过主机ubuntu主机中的浏览器访问在vagrant vm上运行在coreos上的Docker容器

我已经设置了在stream浪VM中运行的coreos。 我想设置私人dockerregistry。 我拉了registry,我可以运行它。 以下是运行registry的输出

core@core-01 ~ $ docker run -p 5000:5000 registry 2014-12-22 01:40:32 [1] [INFO] Starting gunicorn 19.1.0 2014-12-22 01:40:32 [1] [INFO] Listening at: http://0.0.0.0:5000 (1) 2014-12-22 01:40:32 [1] [INFO] Using worker: gevent 2014-12-22 01:40:32 [20] [INFO] Booting worker with pid: 20 2014-12-22 01:40:32 [23] [INFO] Booting worker with pid: 23 2014-12-22 01:40:32 [24] [INFO] Booting worker with pid: 24 2014-12-22 01:40:32 [25] [INFO] Booting worker with pid: 25 2014-12-22 01:40:32 [1] [INFO] 4 workers 22/Dec/2014:01:40:32 +0000 WARNING: Cache storage disabled! 22/Dec/2014:01:40:32 +0000 WARNING: LRU cache disabled! 22/Dec/2014:01:40:32 +0000 DEBUG: Will return docker-registry.drivers.file.Storage 22/Dec/2014:01:40:32 +0000 WARNING: Cache storage disabled! 22/Dec/2014:01:40:32 +0000 WARNING: LRU cache disabled! 22/Dec/2014:01:40:32 +0000 WARNING: Cache storage disabled! 22/Dec/2014:01:40:32 +0000 DEBUG: Will return docker-registry.drivers.file.Storage 22/Dec/2014:01:40:32 +0000 WARNING: LRU cache disabled! 22/Dec/2014:01:40:32 +0000 DEBUG: Will return docker-registry.drivers.file.Storage 22/Dec/2014:01:40:32 +0000 WARNING: Cache storage disabled! 22/Dec/2014:01:40:32 +0000 WARNING: LRU cache disabled! 22/Dec/2014:01:40:32 +0000 DEBUG: Will return docker-registry.drivers.file.Storage 2014-12-22 02:40:32 [1] [INFO] 4 workers 2014-12-22 03:40:31 [1] [INFO] 4 workers 2014-12-22 03:53:42 [1] [INFO] 4 workers 2014-12-22 03:53:42 [1] [INFO] Handling signal: winch 2014-12-22 03:53:42 [1] [INFO] 4 workers 2014-12-22 03:53:43 [1] [INFO] 4 workers 2014-12-22 03:53:43 [1] [INFO] Handling signal: winch 2014-12-22 03:53:43 [1] [INFO] 4 workers 

在我的Ubuntu主机上,我的ifconfig输出显示了下面的内容

 me@mydesktop-Machine-Node00:~$ ifconfig docker0 Link encap:Ethernet HWaddr 56:84:7a:fe:97:99 inet addr:172.17.42.1 Bcast:0.0.0.0 Mask:255.255.0.0 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) eth0 Link encap:Ethernet HWaddr d4:3d:7e:a1:25:1e inet addr:192.168.65.27 Bcast:192.168.65.255 Mask:255.255.255.0 inet6 addr: fe80::d63d:7eff:fea1:251e/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:457483 errors:0 dropped:0 overruns:0 frame:0 TX packets:245109 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:492304997 (492.3 MB) TX bytes:20414914 (20.4 MB) 

链路封装:本地环回

在Ubuntu主机的浏览器上访问172.17.42.1:5000和192.168.65.27:5000显示等待很长时间,但最终没有连接。

我提到这个post,但是我的stream浪者没有提到的post。

我的stream浪文件如下

 # -*- mode: ruby -*- # # vi: set ft=ruby : require 'fileutils' Vagrant.require_version ">= 1.6.0" CLOUD_CONFIG_PATH = File.join(File.dirname(__FILE__), "user-data") CONFIG = File.join(File.dirname(__FILE__), "config.rb") # Defaults for config options defined in CONFIG $num_instances = 1 $update_channel = "alpha" $enable_serial_logging = false $vb_gui = false $vb_memory = 1024 $vb_cpus = 1 # Attempt to apply the deprecated environment variable NUM_INSTANCES to # $num_instances while allowing config.rb to override it if ENV["NUM_INSTANCES"].to_i > 0 && ENV["NUM_INSTANCES"] $num_instances = ENV["NUM_INSTANCES"].to_i end if File.exist?(CONFIG) require CONFIG end Vagrant.configure("2") do |config| # always use Vagrants insecure key config.ssh.insert_key = false config.vm.box = "coreos-%s" % $update_channel config.vm.box_version = ">= 308.0.1" config.vm.box_url = "http://%s.release.core-os.net/amd64- usr/current/coreos_production_vagrant.json" % $update_channel config.vm.provider :vmware_fusion do |vb, override| override.vm.box_url = "http://%s.release.core-os.net/amd64- usr/current/coreos_production_vagrant_vmware_fusion.json" % $update_channel end config.vm.provider :virtualbox do |v| # On VirtualBox, we don't have guest additions or a functional vboxsf # in CoreOS, so tell Vagrant that so it can be smarter. v.check_guest_additions = false v.functional_vboxsf = false end # plugin conflict if Vagrant.has_plugin?("vagrant-vbguest") then config.vbguest.auto_update = false end (1..$num_instances).each do |i| config.vm.define vm_name = "core-%02d" % i do |config| config.vm.hostname = vm_name if $enable_serial_logging logdir = File.join(File.dirname(__FILE__), "log") FileUtils.mkdir_p(logdir) serialFile = File.join(logdir, "%s-serial.txt" % vm_name) FileUtils.touch(serialFile) config.vm.provider :vmware_fusion do |v, override| v.vmx["serial0.present"] = "TRUE" v.vmx["serial0.fileType"] = "file" v.vmx["serial0.fileName"] = serialFile v.vmx["serial0.tryNoRxLoss"] = "FALSE" end config.vm.provider :virtualbox do |vb, override| vb.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"] vb.customize ["modifyvm", :id, "--uartmode1", serialFile] end end if $expose_docker_tcp config.vm.network "forwarded_port", guest: 2375, host: ($expose_docker_tcp + i - 1), auto_correct: true end config.vm.provider :vmware_fusion do |vb| vb.gui = $vb_gui end config.vm.provider :virtualbox do |vb| vb.gui = $vb_gui vb.memory = $vb_memory vb.cpus = $vb_cpus end ip = "172.17.8.#{i+100}" config.vm.network :private_network, ip: ip # Uncomment below to enable NFS for sharing the host machine into the coreos-vagrant VM. #config.vm.synced_folder ".", "/home/core/share", id: "core", :nfs => true, :mount_options => ['nolock,vers=3,udp'] if File.exist?(CLOUD_CONFIG_PATH) config.vm.provision :file, :source => "#{CLOUD_CONFIG_PATH}", :destination => "/tmp/vagrantfile-user-data" config.vm.provision :shell, :inline => "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/", :privileged => true end end end end 

如何在coreos-vagrant上运行docker-registry并使用运行在主机上的浏览器连接到它?

我可以看到你想要做的两个问题。

  1. 从主机操作系统访问在Vagrant VM中运行的Docker容器遇到问题。
  2. 您正在寻找一个Web UI来pipe理您的私人dockerregistry,但是我认为您正在运行的docker图像(库/registry)不提供此function。

第1项:请注意,您正在运行的私人dockerregistry不提供pipe理Web UI。 它在5000端口提供的服务不是一个网站; 它是由命令行泊坞窗用于在您的私人registry中推拉图像。 如果你需要一个pipe理Web UI,你可以考虑运行一个额外的服务,如https://github.com/atc-/docker-registry-web (我还没有尝试,但看起来很有希望)。

第2项:如果您想从Vagrant VM的主机操作系统访问Vagrant-VM托pipe容器的端口 (推测是Windows或OSX,因为如果您的主机操作系统是Linux,您可能不需要Vagrant),那么我build议您打开你的CoreOS Vagrant虚拟机的ssh隧道 ,将dockerregistry端口转发到你的本地主机:

 vagrant ssh -L5000:localhost:5000 -L8080:localhost:8080 -L80:localhost:80 

只要您需要networking访问这些docker集装箱的端口,就让该ssh会话保持打开状态。

当这些端口转发隧道是开放的,你转发的端口将在localhost (即127.0.0.1)上可用。 您不需要像以前那样通过其他IP地址访问它们。 例如,通过浏览器或其他HTTP访问http:// localhost:8080 / ,访问http:// localhost /或运行在端口8080上的应用程序服务器,可以访问运行在Docker容器中的Web服务器客户端如curl。 端口5000在这种情况下可能没有用处,因为可以访问registry的docker命令行实用程序当前不在Windows或OSX上本地运行。 要使用您的私人dockerregistry, 在您的CoreOS Vagrant VM上运行如下所示

 docker tag eb62f9df0657 localhost:5000/myimage docker push localhost:5000/myimage