我正在尝试运行 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 应用程序:
- APP_A : 192.168.4.5:8080
- APP_B : 10.10.10.15:8081
- APP_C : www.app:8082
也是 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 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):
- APP_A : 192.168.4.5:8080
- APP_B : 10.10.10.15:8081
- APP_C : www.app:8082
Applications could use any port because each one "is a different world"
You can not access to your docker applications using its internal ports:
- APP_A : 192.168.4.5:8080
- APP_B : 10.10.10.15:8080
- APP_C : www.app:8080
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 :
- APP_A : 192.168.4.5:8080
- APP_B : 10.10.10.15:8081
- APP_C : www.app:8082
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 有什么区别?
发布评论