通过与NGINX的接口发布Docker,如何更改端口?

我需要在端口12345上创build一个服务,但是指令说

docker run -p 80:8080 swaggerapi/swagger-ui

…我可以改变主机端口 (最终发布是吗?), 从80到12345? 更改主机端口容器端口

所以,我将使用docker run -p 12345:8080 swaggerapi/swagger-ui …它会正常工作?


“好”,对我来说:必须在NGINX的API网关(反向代理)中工作,如下脚本:

 server { server_name api-guide.example.org; root /var/www/teste; index index.html index.htm index.nginx-debian.html; location / { try_files $uri $uri/ @proxy; } location @proxy { try_files $uri =404; rewrite ^/etc$ /$1 break; proxy_pass http://127.0.0.1:12345; } } 

靠近端口12345。

对不起, 我的第一个Docker …它运行正常, http://localhost:12345

因此,要将主机的端口12345映射到容器的端口8080,请运行docker run -p 12345:8080 swaggerapi/swagger-ui & ,如上所述…并使用docker psdocker stop来停止服务。


教程,请参阅https://prakhar.me/docker-curriculum/