在我的工作场所中, docker 在防火墙后面运行,规则只排除了用于服务网页的端口。
容器启动,但网站未打开同一端口。
如果我使用python -m SimpleHTTPServer从运行容器的计算机托管网站,则它可以正常工作。
docker container run --restart=always -p 8081: 8082 -it vue-js-app: latest
最佳答案
从Docker documentation:
发布或公开端口(-p,-expose)
$ docker run -p 127.0.0.1:80:8080/tcp ubuntu bash
This binds port 8080 of the container to TCP port 80 on 127.0.0.1 of the host machine. You can also specify udp and sctp ports. The Docker User Guide explains in detail how to manipulate ports in Docker.
$ docker run --expose 80 ubuntu bash
This exposes port 80 of the container without publishing the port to the host system’s interfaces.
并且,从Docker User Guide:
You also saw how you can bind a container’s ports to a specific port using the -p flag. Here port 80 of the host is mapped to port 5000 of the container:
$ docker run -d -p 80:5000 training/webapp python app.py
因此,作为如何公开可以使用的端口的示例:
docker container run --restart always -p 8081:8082 -it vue-js-app:latest
关于docker - 尝试运行容器时,docker是否需要其他端口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51783283/