Exposing a Docker container port

独自空忆成欢 提交于 2019-12-12 03:01:28

问题


I have been trying to connect to a docker container via ip, but reamins unsuccessful. When I used "docker inspect container-id" I get this result.

My virtual box settings are by default:

Can someone help me resolving this issue?


回答1:


When running docker, you can specify which port(s) you'd like to be accessible to the outside world. Basic syntax is:

docker run -p hostPort:containerPort imageName

or just

docker run -p hostPort imageName

In the first case, externally, hostPort will be used, but inside the container: containerPort will be used. In the second instance, you'd just be using that port both inside and outside your container.

You can also create an image with ports exposed by using the EXPOSE command in a Dockerfile.




回答2:


You need to perform port forwarding or just simply expose port.

Port Forwarding:

docker run -p 2022:22 -p 2375:2375

Expose Port:

docker run -p 22 -p 2375



来源:https://stackoverflow.com/questions/24911380/exposing-a-docker-container-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!