简体   繁体   English

如何让docker容器使用80以外的端口

[英]How to make docker container use port other than 80

I try to deploy self hosted Bitwarden service: https://bitwarden.com/help/article/install-on-premise/我尝试部署自托管 Bitwarden 服务: https://bitwarden.com/help/article/install-on-premise/

When I run install script I get the following error:当我运行安装脚本时,出现以下错误:

docker: Error response from daemon: driver failed programming external connectivity 
on endpoint certbot 
(393789b88f2a15db0ae5fb0d3fdce83e14bd4d4eb890ffff0f946dc607953815): Error starting 
userland proxy: listen tcp4 0.0.0.0:80: bind: address already in use.
ERRO[0000] error waiting for container: context canceled 

Which is expected because I already have NGINX on this VM with a couple of websites and port 80 is being used by the host.这是预料之中的,因为我已经在这个 VM 上有 NGINX 和几个网站,并且主机正在使用端口 80。

I heard that is is possible to make docker container use another host port, instead of 80. That is container will have port 80, but it will be something else externally on the host.我听说有可能让 docker 容器使用另一个主机端口,而不是 80。也就是说,容器将有端口 80,但它将是主机外部的其他端口。 I tried to change the mapping in the install script like 5000:80 instead of 80:80 but I keep getting the same error.我尝试将安装脚本中的映射更改为 5000:80 而不是 80:80,但我一直收到相同的错误。

Am I doing something wrong, or what I am trying to do is not possible?我做错了什么,或者我想做的事情是不可能的?

You can add range to the command and it will use the first available port.您可以向命令添加范围,它将使用第一个可用端口。 so -p 80-100:80 .所以-p 80-100:80

TO get the port that your actually mapping to use docker ps and it will show you what port it's mapped to.获取您实际映射到使用docker ps的端口,它会显示它映射到的端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM