暴露Docker容器端口 [英] Exposing a Docker container port
问题描述
我一直在尝试通过ip连接到docker容器,但失败了.当我使用"docker inspect container-id"时,我得到了这个结果.
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?
推荐答案
在运行docker时,您可以指定外界希望访问哪些端口.基本语法是:
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
或者只是
docker run -p hostPort imageName
在第一种情况下,将在外部使用hostPort
,但在容器内部:将使用containerPort
.在第二种情况下,您将只在容器的内部和外部使用该端口.
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.
您还可以使用 EXPOSE 创建带有暴露端口的映像. Dockerfile中的a>命令.
You can also create an image with ports exposed by using the EXPOSE command in a Dockerfile.
这篇关于暴露Docker容器端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!