简体   繁体   English

如何从Container向主机公开端口?

[英]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 所以我有我的项目,当它安装在主机上时,可以通过(通过嵌入式Tomcat服务器)使登录页面可用

https://127.0.0.1:8443/

Now I installed this in ubuntu container and for installation the command I used was 现在我将其安装在ubuntu容器中,安装时使用的命令是

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 并再次尝试了相同的URL,但是没有运气

What I see is HTTP 404 from Apache . 我看到的是来自Apache HTTP 404 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 . 语法为-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. 应该管用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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