在docker run中发布8080:80和8080:8080有什么区别? [英] what is the difference between publishing 8080:80 and 8080:8080 in a docker run?

查看:1401
本文介绍了在docker run中发布8080:80和8080:8080有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行詹金斯容器。我使用了 docker run-永远重启–name myjenkins -p 8080:80 jenkins,但无法在 http:// localhost :8080 在浏览器上。如果我使用docker run --restart always --name myjenkins -p 8080:8080 jenkins,则可以访问jenkins网址。

I am trying to run jenkins container. I used "docker run --restart always --name myjenkins -p 8080:80 jenkins" but cannot access jenkins at http://localhost:8080 on browser. If I use docker run --restart always --name myjenkins -p 8080:8080 jenkins, I can access the jenkins url.

预先感谢

推荐答案

8080:80表示在容器中您正在使用端口80,并将该端口转发到主机的8080端口。因此,在方案2中的任何位置,您都在容器内的端口80上运行Jenkins,并且在容器内的端口8080上运行Jenkins,并将其暴露在主机的同一端口上。
例如,如果我在容器中运行mysql,则可能会使用8080:3306,因此mysql将在端口3306上运行,但在主机的8080上暴露,但是如果为mysql选择8080:80,则它可能无法工作,因为按照mysql的代码,它绑定在端口3306而不是端口80上。在您的詹金斯案例中,情况也是如此。

8080:80 refers that in the container you are using port 80 and you are forwarding that port to host machine's 8080 port. So you are running Jenkins on port 80 inside your container wherever in scenario 2 you are running Jenkins on port 8080 inside the container and exposing it over the same port on host machine. For example if I am running mysql in container I may use 8080:3306 so mysql would be running on port 3306 but exposed on 8080 of host machine but if choose it to be 8080:80 for mysql it may not work because as per the code of mysql it binds itself on port 3306 not port 80. Same is the scenario in your case of Jenkins too.

这篇关于在docker run中发布8080:80和8080:8080有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆