如何从主机访问Docker容器的Web服务器

编程入门 行业动态 更新时间:2024-10-25 14:32:58
本文介绍了如何从主机访问Docker容器的Web服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我在boot2docker 1.3.1下运行。

我有一个Docker容器通过 uwsgi --http:8080运行Web服务器。

如果我附加到容器,我可以使用 lynx 127.0.0.1浏览网站:8080 所以我知道服务器正在工作。

我运行了我的容器:

$ docker run -itP --expose 8080 uwsgi_app:0.2

它有以下详细信息:

$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5248ad86596d uwsgi_app:0.2bash11分钟前Up 11分钟0.0.0.0:49159->8080/tcp cocky_hypatia $ docker inspect --format'{{.NetworkSettings.IPAddress}}'5248ad86596d 172.17.0.107

我以为我可以从我的主机访问该网站,转到 172.17.0.107:49159 。

这不行。我在Chrome中看到连接...,无处可寻。

我做错了什么?

解决方案

好的,愚蠢的我,我在文档中找到了boot2docker docs.docker/installation/mac/#container-port-redirection

我需要使用boot2docker vm的ip地址,而不是容器的ip,即

$ boot2docker ip 192.168.59.103

,我可以从主机浏览我的网站 http:/我不需要添加任何路由

在主机上

I'm running under boot2docker 1.3.1.

I have a Docker container running a web server via uwsgi --http :8080.

If I attach to the container I can browse the web site using lynx 127.0.0.1:8080 so I know the server is working.

I ran my container with:

$ docker run -itP --expose 8080 uwsgi_app:0.2

It has the following details:

$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5248ad86596d uwsgi_app:0.2 "bash" 11 minutes ago Up 11 minutes 0.0.0.0:49159->8080/tcp cocky_hypatia $ docker inspect --format '{{ .NetworkSettings.IPAddress }}' 5248ad86596d 172.17.0.107

I thought I could access that web site from my host by going to 172.17.0.107:49159.

This does not work. I just see 'connecting...' in Chrome, getting nowhere.

What am I doing wrong?

解决方案

Ok, stupid me, I found the answer in the docs for boot2docker docs.docker/installation/mac/#container-port-redirection

I needed to use the ip address of the boot2docker vm, rather than the ip of the container, i.e.

$ boot2docker ip 192.168.59.103

and I am able to browse my site from the host at 192.168.59.103:49159/

I did not need to add any route on the host

更多推荐

如何从主机访问Docker容器的Web服务器

本文发布于:2023-11-08 14:19:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569614.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:容器   主机   服务器   Docker   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!