简体   繁体   中英

How do I expose port from Container to host?

so I have my project which when installed on host makes login page available (via embedded Tomcat server) as

https://127.0.0.1:8443/

Now I installed this in ubuntu container and for installation the command I used was

docker run -it --name lp --dns=122.17.213.214 --dns=122.26.00.10 --dns-search=corp.sfc.san -p 8080:8443 -v ~/Downloads/logs:/logs -v ~/Downloads:/installers ubuntu /bin/bash

When I did that, I was not able to reach this on my host browser, what I tried was

https://my-docker-machine-ip:8443/ # I am using Mac OSX

Next, I thought to provide exact mapping and I tried

docker run -it --name lp --dns=122.17.213.214 --dns=122.26.00.10 --dns-search=corp.sfc.san -p 192.168.99.100:8443:8443 -v ~/Downloads/logs:/logs -v ~/Downloads:/installers ubuntu /bin/bash  

and tried the same URL again, but no luck

What I see is HTTP 404 from Apache . What am I missing?

However within the container, I see log that tells me that server is running

11 May 2016 22:19:19,166 [INFO ] [main] EmbeddedWebServer    | Starting tomcat server on port 8443 ...

The syntax is -p hostPort:ContainerPort . Your first example had the right syntax but the 'wrong' port (compared to what you were expecting).

Instead of:

docker run -it --name lp --dns=122.17.213.214 --dns=122.26.00.10 --dns-search=corp.sfc.san -p 8080:8443 -v ~/Downloads/logs:/logs -v ~/Downloads:/installers ubuntu /bin/bash

Use:

docker run -it --name lp --dns=122.17.213.214 --dns=122.26.00.10 --dns-search=corp.sfc.san -p 8443:8443 -v ~/Downloads/logs:/logs -v ~/Downloads:/installers ubuntu /bin/bash

Then

https://my-docker-machine-ip:8443/ # I am using Mac OSX

should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM