Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

docker

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.

Thanks in advance

like image 488
YashRao Avatar asked Nov 29 '22 08:11

YashRao


2 Answers

Without Docker

imagenro1

  • 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.com:8082

With Docker

enter image description here

  • 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.com: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.

enter image description here

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.com: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 ...

like image 120
JRichardsz Avatar answered Dec 04 '22 07:12

JRichardsz


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.

like image 45
Vikas Kumar Avatar answered Dec 04 '22 05:12

Vikas Kumar