Docker Nginx映像启动,但失败并出现错误;“已在使用的端口”;

Docker Nginx映像启动,但失败并出现错误;“已在使用的端口”;,docker,nginx,containers,Docker,Nginx,Containers,我有带图像的docker容器。我将5个Nginx配置文件推送到这个容器中,但它不工作,并且由于容器中的“端口已在使用”而失败。每个配置文件都包含不同的端口,但启动时失败 错误。日志有: 019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:80 failed (98: Address in use) 2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:80 failed (98: Address i

我有带图像的docker容器。我将5个Nginx配置文件推送到这个容器中,但它不工作,并且由于容器中的“端口已在使用”而失败。每个配置文件都包含不同的端口,但启动时失败

错误。日志有:

019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:80 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:80 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2447 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2447 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2450 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2450 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2448 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2448 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2449 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2449 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:80 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:80 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2447 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2447 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2450 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2450 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2448 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2448 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2449 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2449 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:80 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:80 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2447 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2447 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2450 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2450 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2448 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2448 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2449 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2449 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:80 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:80 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2447 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2447 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2450 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2450 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2448 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2448 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2449 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2449 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:80 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:80 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2447 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2447 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2450 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2450 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2448 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2448 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to 0.0.0.0:2449 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: bind() to [::]:2449 failed (98: Address in use)
2019/10/13 14:57:17 [emerg] 21#21: still could not bind()
netstat-ltnp
info:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.11:33623        0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:2447            0.0.0.0:*               LISTEN      9/nginx: master pro
tcp        0      0 0.0.0.0:2448            0.0.0.0:*               LISTEN      9/nginx: master pro
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      9/nginx: master pro
tcp        0      0 0.0.0.0:2449            0.0.0.0:*               LISTEN      9/nginx: master pro
tcp        0      0 0.0.0.0:2450            0.0.0.0:*               LISTEN      9/nginx: master pro
tcp        0      0 :::2447                 :::*                    LISTEN      9/nginx: master pro
tcp        0      0 :::2448                 :::*                    LISTEN      9/nginx: master pro
tcp        0      0 :::80                   :::*                    LISTEN      9/nginx: master pro
tcp        0      0 :::2449                 :::*                    LISTEN      9/nginx: master pro
tcp        0      0 :::2450                 :::*                    LISTEN      9/nginx: master pro
正如我看到的,Nginx启动了一些东西,但是如何检查它是什么呢

Docker ps:

您有一个id为(PID)的进程,该进程占用了该端口。 您可以使用
ps-p9-ocomm=
获取此进程的命令行

我想是docker。在这种情况下,请尝试
docker ps
获取正在运行的docker容器的列表

您可以通过
kill-9
终止这个进程


更新:我已尝试通过
docker run nginx:1.17.4-alpine运行容器,但没有任何问题。如果您生成自定义映像或使用与默认值不同的其他设置或配置,则需要对其进行说明。

docker ps
结果添加到问题中显示您的dockerfile,似乎Nginx尝试重新启动,而另一个进程或Nginx已占用该端口。@adii我已在此处添加了它,请检查主文件是否丢失
/opt/startup.sh
@adii是的,对不起,忘记了@adii我应该注意,对于其他同事,它启动时没有任何问题。我想这对docker来说并不重要,因为容器化,但在Windows10和Ubuntu18.04(客户端)上它可以工作,在macOS上它不能工作。