Exposing a Docker container port

2019-09-17 01:47发布

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.

Docker container port

My virtual box settings are by default:

Virtual box settings

Can someone help me resolving this issue?

2条回答
Anthone
2楼-- · 2019-09-17 02:07

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

查看更多
家丑人穷心不美
3楼-- · 2019-09-17 02:19

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.

查看更多
登录 后发表回答