尝试 运行 容器时 docker 是否需要额外的端口?

Does docker require additional port when try to run 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