【问题标题】:docker run nginx:latest hangs indefinitelydocker run nginx:latest 无限期挂起
【发布时间】:2020-03-20 15:00:31
【问题描述】:

edit:其他容器正常运行。 docker run hello-world 工作正常。

我正在尝试运行最新的 nginx docker 映像。它无限期地挂起。我已经在 2 个单独的全新安装的 ubuntu 虚拟机上尝试过这个。我不知道如何进行。任何帮助将不胜感激。

docker run nginx:latest
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
68ced04f60ab: Already exists 
28252775b295: Already exists 
a616aa3b0bf2: Already exists 
Digest: sha256:2539d4344dd18e1df02be842ffc435f8e1f699cfc55516e2cf2cb16b7a9aea0b
Status: Downloaded newer image for nginx:latest
...

...它在最后挂起。

还有一些 netstat 来验证端口 80 和 443 是否空闲。

sudo netstat -tulpn
[sudo] password for josh: 
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      387/systemd-resolve 
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      471/cupsd           
tcp6       0      0 ::1:631                 :::*                    LISTEN      471/cupsd           
udp        0      0 127.0.0.53:53           0.0.0.0:*                           387/systemd-resolve 
udp        0      0 0.0.0.0:68              0.0.0.0:*                           6179/dhclient       
udp        0      0 0.0.0.0:631             0.0.0.0:*                           685/cups-browsed    
udp        0      0 0.0.0.0:46233           0.0.0.0:*                           485/avahi-daemon: r 
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           485/avahi-daemon: r 
udp6       0      0 :::5353                 :::*                                485/avahi-daemon: r 
udp6       0      0 :::35115                :::*                                485/avahi-daemon: r 

【问题讨论】:

  • 你在运行nginx容器时没有绑定80和443端口?

标签: docker ubuntu nginx


【解决方案1】:

当你执行这个命令docker run nginx:latest你实际上是在附加模式下运行它,这意味着

  • stdout 和 stderr 的所有日志都将打印在屏幕上
  • 如果您使用Ctrl + cCmd + c 退出命令,容器将停止。

因此,该命令似乎挂起,因为不再打印日志。

您可以尝试运行以下命令

docker run -it -d \
  --name nginx_container \
  -p 80:80 \
  -p 443:443 \
  nginx:latest

请注意,此命令将创建一个正在运行的 nginx 容器,名称为 nginx_container 在后台运行(分离模式)。再次运行此命令将导致The container name "/nginx_container" is already in use by container 的投诉。

要停止并删除该容器,请运行以下命令

docker stop nginx_container
docker rm nginx_container

【讨论】:

    猜你喜欢
    • 2017-06-29
    • 2011-05-07
    • 2021-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-29
    • 2019-08-01
    • 1970-01-01
    相关资源
    最近更新 更多