但是为什么我必须附加:4000?
我在这里遵循https://docs.docker.com/get-started/part4/
的docker入门指南我敢肯定我已经正确地完成了所有事情,但是想知道为什么在部署之后我无法连接查看该应用程序。
我已将环境设置为我的VM myvm1,以参考以下命令。
docker容器ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
099e16249604 beresj/getting-started:part2 "python app.py" 12 seconds ago Up 12 seconds 80/tcp getstartedlab_web.5.y0e2k1r1ev47u24e5iufkyn3i
6f9a24b343a7 beresj/getting-started:part2 "python app.py" 12 seconds ago Up 12 seconds 80/tcp getstartedlab_web.3.1pls3osj3uhsb5dyqtt4ts8j6
docker image ls -a
REPOSITORY TAG IMAGE ID CREATED SIZE
beresj/getting-started <none> e290b6208c21 22 hours ago 131MB
docker stack ls
NAME SERVICES ORCHESTRATOR
getstartedlab 1 Swarm
docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
myvm1 * virtualbox Running tcp://192.168.99.100:2376 v18.09.6
myvm2 - virtualbox Running tcp://192.168.99.101:2376 v18.09.6
docker stack ps getstartedlab
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
vkxx79fh3h85 getstartedlab_web.1 beresj/getting-started:part2 myvm2 Running Running 3 minutes ago
qexbaa3wz0pd getstartedlab_web.2 beresj/getting-started:part2 myvm2 Running Running 3 minutes ago
1pls3osj3uhs getstartedlab_web.3 beresj/getting-started:part2 myvm1 Running Running 3 minutes ago
ucuwen1jrncf getstartedlab_web.4 beresj/getting-started:part2 myvm2 Running Running 3 minutes ago
y0e2k1r1ev47 getstartedlab_web.5 beresj/getting-started:part2 myvm1 Running Running 3 minutes ago
卷曲192.168.99.100
curl: (7) Failed to connect to 192.168.99.100 port 80: Connection refused
码头工人信息
Containers: 2
Running: 2
Paused: 0
Stopped: 0
Images: 1
Server Version: 18.09.6
...
Swarm: active
NodeID: 0p9qrax9h3by0fupat8ufkfbq
Is Manager: true
ClusterID: 7vnqdk85n8jx6fqck9k7dv2ka
Managers: 1
Nodes: 2
Default Address Pool: 10.0.0.0/8
...
Node Address: 192.168.99.100
Manager Addresses:
192.168.99.100:2377
...
Kernel Version: 4.14.116-boot2docker
Operating System: Boot2Docker 18.09.6 (TCL 8.2.1)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 989.4MiB
Name: myvm1
我希望看到我在本地计算机上而不是在群集中的VM上运行时能够看到的内容(我认为我的术语正确吗?)
不确定如何检查打开的端口。
再次:如果我简单地删除堆栈,取消设置docker-machine环境,然后运行,这将起作用:
docker stack deploy -c docker-compose.yml getstartedlab
不在虚拟机上。
先谢谢您。 (此外,我是新手,因此请参阅入门指南,感谢您的帮助)
如果将:4000附加到URL中的VM IP(例如:192.168.99.100:4000或192.168.99.101:4000),它将起作用。它显示myvm1的'docker container ls'中列出的两个容器ID,其他三个来自myvm2。谁能告诉我为什么我必须追加4000?是因为我在docker-compose.yml中有端口:“ 4000:80”吗?
答案 0 :(得分:1)
不确定这是否有帮助,但是如果您使用docker inspect <instance_id_here>
,则可以看到暴露了哪些端口。
暴露的端口不是开放端口。您需要将主机端口绑定到docker-compose.yml中的容器端口,才能将其打开。