在docker run中发布8080:80和8080:8080有什么区别?

编程入门 行业动态 更新时间:2024-10-27 00:33:14
本文介绍了在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 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有什么区别?

本文发布于:2023-08-07 14:00:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319448.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别   run   docker

发布评论

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

>www.elefans.com

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