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

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

问题描述

我正在尝试运行 jenkins 容器.我使用了docker run --restart always --name myjenkins -p 8080:80 jenkins"但无法在

使用 Docker

  • 应用程序可以使用任何端口,因为每个端口都是不同的世界"

  • 无法访问使用其内部端口的 docker 应用程序:

    • APP_A : 192.168.4.5:8080
    • APP_B : 10.10.10.15:8080
    • APP_C :

      为此,您可以使用 -p 参数

      • docker run -d -p 8080:8080 APP_A ...
      • docker run -d -p 8081:8080 APP_B ...
      • docker run -d -p 8082:8080 APP_C ...

      此后,您可以使用其新端口访问您的 docker 应用程序:

      <块引用>

      也是 docker-compose & 时的常见错误当一个 docker 应用程序需要连接到另一个 docker 应用程序时,使用 docker 网络是使用 localhost 而不是 ip.如您所见,您需要使用 ip 或域 + 外部端口 而不是 localhost:8080


      <块引用>

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

      • 对于 8080:80,您希望您的应用程序使用或从容器内的 80 内部端口开始.
      • 对于 8080:8080,您希望您的应用程序使用或从容器内的 8080 内部端口开始.

      您只需要研究 jenkins 使用的内部容器端口是什么,并将其放入 docker run -p ...

      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.

      Thanks in advance

      解决方案

      Without Docker

      • Each application must use a different port.

      • You can access to your application using directly its ports (if are available of course):

      With Docker

      • Applications could use any port because each one "is a different world"

      • You can not access to your docker applications using its internal ports:

      Because for instance, 8080 of APP_B is only visible inside APP_B container. No body can access to this applications.

      In order to access to your docker applications, You must explicitly establish a relationship between:

      Linux host ports <-> inside containers ports.

      To do that you could use -p parameter

      • docker run -d -p 8080:8080 APP_A ...
      • docker run -d -p 8081:8080 APP_B ...
      • docker run -d -p 8082:8080 APP_C ...

      After this you could access to your docker applications using its new ports :

      Also a common error when docker-compose & docker network are used is use localhost instead ip when a docker app needs to connect to another docker app. As you can see you need to use ip or domain + external port instead localhost:8080


      what is the difference between publishing 8080:80 and 8080:8080 in a docker run?

      • With 8080:80 you expect that your application uses or start with the 80 internal port inside container.
      • With 8080:8080 you expect that your application uses or start with the 8080 internal port inside container.

      You just need to research what is the internal container port used by your jenkins and put it in docker run -p ...

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

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