docker - 尝试运行容器时,docker是否需要其他端口?

标签 docker docker-container

在我的工作场所中, 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/

相关文章:

Docker 在 Windows 上的 Docker 内部

docker - 重新连接到Docker容器中正在运行的bash

node.js - Docker 容器内的 Nodemon

docker - 无法停止 docker couchbase-community

maven - 在Maven构建期间如何从属性文件创建kubernetes configmap?

nginx - 以零停机时间更新容器中的 Nginx 配置文件

docker - 在不杀死容器的情况下杀死 Docker 容器内的 Web 服务器等正在运行的进程

docker - 如何在 Ubuntu 18 上安装较旧的 Docker 版本(18.06.2)?

python - 无法在 docker 中重新创建 Conda 环境

docker - 如何创建具有自定义根卷大小的 docker 容器?