无法从主机访问Docker群中的Web服务器 [英] Unable to reach web server in Docker swarm from the host
问题描述
我开始在macOS上使用Docker,并在尝试完成入门指南的第4部分.我创建了两个额外的虚拟机(myvm1
和myvm2
),将myvm1
设置为swarm manager,将myvm2
设置为worker.
然后,使用本教程第3部分中的docker-compose.yml
部署了具有5个Flask Web服务器的堆栈.进程似乎可以正常启动,并且分布在两台计算机之间,但是我无法使用浏览器从主机访问这些进程.
I'm starting out using Docker on macOS, and get stuck when trying to complete part 4 of the Get Started guide. I have created two extra virtual machines (myvm1
and myvm2
), set myvm1
as swarm manager, and myvm2
as a worker.
I have then deployed a stack with 5 Flask web servers using the docker-compose.yml
from part 3 of the tutorial. The processes seem to start fine, and are distributed between the two machines, but I am not able to reach them from the host using a browser.
我应该如何配置端口转发/网络,使其能够从运行docker容器的虚拟机主机访问群集中的Web服务器?
How should I configure the port forwarding/network to be able to reach the web servers in the swarm from the host of the virtual machines running the docker container?
以下是我已运行的命令列表,其中一些命令具有输出结果.
The following is a list of commands that I have run, some with resulting output.
$ docker-machine create --driver virtualbox myvm1
$ docker-machine create --driver virtualbox myvm2
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
myvm1 - virtualbox Running tcp://192.168.99.100:2376 v18.09.0
myvm2 - virtualbox Running tcp://192.168.99.101:2376 v18.09.0
$ docker-machine ssh myvm1 "docker swarm init --advertise-addr 192.168.99.100"
$ docker-machine ssh myvm2 "docker swarm join --token <my-token-inserted-here> 192.168.99.100:2377"
$ eval $(docker-machine env myvm1)
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
myvm1 * virtualbox Running tcp://192.168.99.100:2376 v18.09.0
myvm2 - virtualbox Running tcp://192.168.99.101:2376 v18.09.0
$ docker stack deploy -c docker-compose.yml getstartedlab
$ docker stack ps getstartedlab
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
it9asz4zpdmi getstartedlab_web.1 mochr/test_repo:friendly_hello myvm2 Running Preparing 18 seconds ago
645gvtnde7zz getstartedlab_web.2 mochr/test_repo:friendly_hello myvm1 Running Preparing 18 seconds ago
fpq6cvcf3e0e getstartedlab_web.3 mochr/test_repo:friendly_hello myvm2 Running Preparing 18 seconds ago
plkpximnpobf getstartedlab_web.4 mochr/test_repo:friendly_hello myvm1 Running Preparing 18 seconds ago
gr2p8a0asatb getstartedlab_web.5 mochr/test_repo:friendly_hello myvm2 Running Preparing 18 seconds ago
docker-compose.yml
:
version: "3"
services:
web:
image: mochr/test_repo:friendly_hello
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "4000:80"
networks:
- webnet
networks:
webnet:
推荐答案
It looks like this is a known problem with the current version of boot2docker: https://github.com/docker/machine/issues/4608
解决方法是使用基于不需要boot2docker的机器(例如AWS,DigitalOcean等)的群集,等到发布更高版本的boot2docker,或使用更早版本的boot2docker,如中所述该链接.要使用早期版本:
The workaround is either to use a swarm based on machines that do not require boot2docker (e.g. AWS, DigitalOcean, etc.), wait until a newer version of boot2docker is released, or use an earlier version of boot2docker, as described in that link. To use an earlier version:
export VIRTUALBOX_BOOT2DOCKER_URL=https://github.com/boot2docker/boot2docker/releases/download/v18.06.1-ce/boot2docker.iso
在使用docker-machine创建虚拟机之前. (先删除现有的虚拟机,然后使用该导出,然后再删除docker-machine create myvm1
)
before creating your virtual machines with docker-machine. (Remove your existing virtual machines first, then use that export, then docker-machine create myvm1
)
然后,您应该能够调出堆栈并访问位于192.168.99.100:4000或192.168.99.101:4000(或docker-machine ls显示的任何IP地址)的容器
Then, you should be able to bring up your stack and access your containers at either 192.168.99.100:4000 or 192.168.99.101:4000 (or whatever IP addresses are revealed by docker-machine ls)
这篇关于无法从主机访问Docker群中的Web服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!