码头工人。错误:无法启动容器:端口已分配

新手上路,请多包涵

我正在使用 Docker,当我第一次创建容器时,我设法正确使用它。今天我重新启动了我的计算机并让自己再次使用 Docker 容器。

我试图像这样“激活”容器:

 docker run -it --rm -p 5000:5000 -v `pwd`:/app myproject

这是我收到的信息:

 WARNING: Local (127.0.0.1) DNS resolver found in resolv.conf and containers can't use it. Using default external servers : [8.8.8.8 8.8.4.4]
2014/07/28 12:34:32 Error: Cannot start container a152dd9040ab4be0f20ace96ba4a9b0a3c50fa89034512c2b9fcb986db912027: port has already been allocated

所以我试图找出正在侦听端口 5000 的进程并将其杀死。像这样:

 # netstat -tulpn | grep :5000
tcp6       0      0 :::5000                 :::*                    LISTEN    3992/docker.io
# kill -9 3992

我还尝试重新启动 docker 服务,如下所示:

 sudo service docker.io restart

但这些事情都没有奏效。尝试激活我的容器时,我仍然收到相同的错误消息:

 # docker run -it --rm -p 5000:5000 -v `pwd`:/app myproj
WARNING: Local (127.0.0.1) DNS resolver found in resolv.conf and containers can't use it. Using default external servers : [8.8.8.8 8.8.4.4]
2014/07/28 12:34:14 Error: Cannot start container b28ac5c4a425068ac1827bade6dd89e95be32f3e94c982300eba006822971ab1: port has already been allocated

谷歌搜索解决方案我发现这似乎是一个已知 问题,但也许你可以帮助我找到解决这个问题的方法。

更新:

正如@Marcus Hughes 所要求的,这是 docker ps 的输出:

 $ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                    NAMES
3fdfc9ecf30f        7e0ca0814a33        /bin/sh -c composer    4 hours ago         Up About an hour    0.0.0.0:5000->5000/tcp   naughty_galileo

如果我这样做 docker ps -a ,这就是我得到的:

 $ sudo docker ps -a
CONTAINER ID        IMAGE                        COMMAND                CREATED              STATUS              PORTS                    NAMES
69400a0e21f5        stenocaption-server:latest   /bin/sh -c composer    About a minute ago   Exit 0                                       agitated_feynman
a3c352d48ab5        stenocaption-server:latest   /bin/sh -c composer    6 minutes ago        Exit 0                                       grave_shockley
4c3c823bda55        stenocaption-server:latest   /bin/sh -c composer    2 hours ago          Exit 0                                       condescending_heisenberg
b9083a0af2cd        7e0ca0814a33                 /bin/sh -c composer    2 hours ago          Exit 0                                       kickass_lumiere
0d51ea8c4377        7e0ca0814a33                 /bin/sh -c composer    2 hours ago          Exit 0                                       sick_ritchie
a152dd9040ab        7e0ca0814a33                 /bin/sh -c composer    2 hours ago          Exit 0                                       happy_thompson
b28ac5c4a425        7e0ca0814a33                 /bin/sh -c composer    2 hours ago          Exit 0                                       cocky_franklin
d449f40487ca        7e0ca0814a33                 /bin/sh -c composer    2 hours ago          Exit 0                                       evil_torvalds
b485da98ca6d        7e0ca0814a33                 /bin/sh -c composer    2 hours ago          Exit 0                                       tender_nobel6
8b73b154c8aa        7e0ca0814a33                 /bin/sh -c composer    2 hours ago          Exit 0                                       dreamy_ptolemy
10d327c46d95        7e0ca0814a33                 /bin/sh -c composer    2 hours ago          Exit 0                                       boring_morse
a3397c0c4dfb        7e0ca0814a33                 /bin/sh -c composer    2 hours ago          Exit 0                                       thirsty_engelbart
e6440629fac1        7e0ca0814a33                 /bin/sh -c composer    3 hours ago          Exit 0                                       distracted_bohr
cb718204384e        7e0ca0814a33                 /bin/sh -c composer    3 hours ago          Exit 0                                       nostalgic_mclean
ca62ccc30227        7e0ca0814a33                 /bin/sh -c composer    3 hours ago          Exit 0                                       evil_heisenberg
83ed0727883f        7e0ca0814a33                 /bin/sh -c composer    3 hours ago          Exit 0                                       nostalgic_curie
1100e926ef29        7e0ca0814a33                 /bin/sh -c composer    3 hours ago          Exit 0                                       tender_nobel
1ed76e31d8f5        7e0ca0814a33                 /bin/sh -c composer    3 hours ago          Exit 0                                       grave_hawking
ad429a4ab116        7e0ca0814a33                 /bin/sh -c composer    3 hours ago          Exit 0                                       condescending_nobel
5790e0e9c21f        7e0ca0814a33                 /bin/sh -c composer    4 hours ago          Exit 0                                       boring_curie
3fdfc9ecf30f        7e0ca0814a33                 /bin/sh -c composer    4 hours ago          Up About an hour    0.0.0.0:5000->5000/tcp   naughty_galileo
7372b8327065        b0d5a13e5ea7                 /bin/sh -c apt-get-i   40 hours ago         Exit 127                                     high_torvalds
d4482ca96df9        10aac624035d                 /bin/sh -c apt-get i   40 hours ago         Exit 0                                       sad_pare
0ae7489bd53e        6edd40908159                 /bin/sh -c apt-get i   41 hours ago         Exit 0                                       dreamy_davinci
13c1a8670908        ubuntu:14.04                 /bin/sh -c apt-get u   41 hours ago         Exit 0                                       loving_babbage
18e20ff7f4ec        ubuntu:14.04                 /bin/sh -c apt-get u   41 hours ago         Exit 1                                       stupefied_poincare
0965776b2ee9        ubuntu:14.04                 /bin/sh -c apt-get u   41 hours ago         Exit 1                                       goofy_davinci
aa3d871f6d1c        ubuntu:14.04                 /bin/sh -c apt-get u   41 hours ago         Exit 1                                       insane_pasteur
cb266936771d        ubuntu:14.04                 /bin/sh -c apt-get u   41 hours ago         Exit 1                                       distracted_turing
10d25a9c965b        ubuntu:14.04                 /bin/sh -c apt-get u   41 hours ago         Exit 1                                       kickass_ptolemy
729afe65b3f5        ubuntu:14.04                 /bin/sh -c apt-get u   42 hours ago         Exit 1                                       dreamy_tesla
a53c5707e667        ubuntu:14.04                 /bin/sh -c apt-get u   42 hours ago         Exit 1                                       ecstatic_bohr
ec97aaae1bda        ubuntu:14.04                 /bin/sh -c apt-get u   42 hours ago         Exit 1                                       romantic_bell
13fe8539439c        ubuntu:14.04                 /bin/sh -c apt-get u   42 hours ago         Exit 1                                       romantic_shockley
deaff10c2ed3        ubuntu:14.04                 /bin/sh -c apt-get u   42 hours ago         Exit 1                                       trusting_shockley
c49494c24595        ubuntu:14.04                 /bin/sh -c apt-get u   42 hours ago         Exit 1                                       loving_bell
3972c67fbd92        ubuntu:14.04                 /bin/sh -c apt-get u   42 hours ago         Exit 1                                       stupefied_euclid

原文由 Xar 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 538
2 个回答

From the docker ps output, there is a container which is listening on port 5000 as you can see from the 0.0.0.0:5000->5000/tcp under the ports column .

你可以用 docker kill container 杀死这个容器。此时它将释放端口。在你的情况下:

 docker kill 3fdfc9ecf30f

原文由 Marcus Hughes 发布,翻译遵循 CC BY-SA 3.0 许可协议

我已经通过重新启动 docker 服务来修复它:

sudo service docker restart

注意:顺便说一下,我使用的是 Linux Mint。

原文由 pedromorfeu 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题