简体   繁体   English

无法让docker通过互联网接受请求

[英]Can't get docker to accept request over the internet

So, I'm trying to get Jenkins working inside of docker as an exercise to get experience using docker. 所以,我试图让Jenkins在docker中工作,以获得使用docker获得经验的练习。 I have a small linux server, running Ubuntu 14.04 in my house (computer I wasn't using for anything else), and have no issues getting the container to start up, and connect to Jenkins over my local network. 我有一个小的Linux服务器,在我家里运行Ubuntu 14.04(我没有使用其他任何东西的计算机),并且没有问题让容器启动,并通过我的本地网络连接到Jenkins。

My issue comes in when I try to connect to it from outside of my local network. 当我尝试从本地网络外部连接到它时,我的问题就出现了。 I have port 8080 forwarded to the serve with the container, and if I run a port checker it says the port is open. 我将端口8080转发到带有容器的服务器,如果我运行端口检查器,它说端口是打开的。 However, when I actually try and go to my-ip:8080, I will either get nothing if I started the container just with -p 8080:8080 or "Error: Invalid request or server failed. HTTP_Proxy" if I run it with -p 0.0.0.0:8080:8080. 但是,当我实际尝试转到my-ip:8080时,如果我使用-p 8080:8080启动容器或“错误:无效请求或服务器失败.HTTP_Proxy”,如果我使用 - 运行它,我将得不到任何结果p 0.0.0.0:8080:8080。

I wanted to make sure it wasn't jenkins, so I tried getting just a simple hello world flask application to work, and had the exact same issue. 我想确保它不是jenkins,所以我试着让一个简单的hello world flask应用程序工作,并且有完全相同的问题。 Any recommendations? 有什么建议? Do I need to add anything extra inside Ubuntu to get it to allow outside connections to go to my containers? 我是否需要在Ubuntu中添加任何额外内容以使其允许外部连接转到我的容器?

EDIT: I'm also just using the official Jenkins image from docker hub. 编辑:我也只是使用docker hub的官方Jenkins图像。

If you are running this: 如果您正在运行此:

docker run -p 8080:8080 jenkins

Then to connect to jenkins you will have to connect to (in essence you are doing port forwarding): 然后连接到jenkins你必须连接到(实质上你正在进行端口转发):

http://127.0.0.1:8080 or http://localhost:8080

If you are just running this: 如果你刚刚运行这个:

docker run jenkins

You can connect to jenkins using the container's IP 您可以使用容器的IP连接到jenkins

http://<containers-ip>:8080

The Dockerfile when the Jenkins container is built already exposes port 8080 构建Jenkins容器时的Dockerfile已暴露端口8080

The Docker Site has a great amount of information on container networks. Docker站点有大量关于容器网络的信息。 https://docs.docker.com/articles/networking https://docs.docker.com/articles/networking

"By default Docker containers can make connections to the outside world, but the outside world cannot connect to containers." “默认情况下,Docker容器可以与外部世界建立连接,但外部世界无法连接到容器。”

You will need to provide special options when invoking docker run in order for containers to accept incoming connections. 在调用docker run时,您需要提供特殊选项,以便容器接受传入连接。

Use the -P or --publish-all=true|false for containers to accept incoming connections. 对容器使用-P--publish-all=true|false来接受传入连接。

The below should allow you to access it from another network: 以下应允许您从其他网络访问它:

docker run -P -p 8080:8080 jenkins 

if you can connect to Jenkins over local network from a machine different than the one docker is running on but not from outside your local network, then the problem is not docker. 如果您可以通过本地网络从不同于一个docker运行但不是来自本地网络之外的计算机连接到Jenkins,则问题不在于docker。 In this case the problem is what ever machine who is receiving outside connection (normally your router, modem or ...) does not know to which machine the outside request should be forwarded. 在这种情况下,问题是接收外部连接的机器(通常是您的路由器,调制解调器或......)不知道外部请求应转发到哪台机器。

You have to make sure you are forwarding the proper port on your external IP to proper port on the machine which is running Docker. 您必须确保将外部IP上的正确端口转发到运行Docker的计算机上的正确端口。 This can be normally done on your internet modem/router. 这通常可以在您的互联网调制解调器/路由器上完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM