我正在使用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
谷歌搜索解决方案我发现这似乎是一个已知的issue,但也许你可以帮助我找到摆脱这个问题的方法。
更新
正如@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
答案 0 :(得分:47)
从docker ps
输出,有一个正在侦听端口5000
的容器,您可以从0.0.0.0:5000->5000/tcp
列下的ports
看到。
您可以使用docker kill container
终止此容器。此时它将释放端口。在你的情况下:
docker kill 3fdfc9ecf30f
答案 1 :(得分:8)
我已经通过重启docker服务修复了它:
sudo service docker restart
注意:顺便说一下,我正在使用Linux Mint。
答案 2 :(得分:7)
我遇到的一个原因是在某些版本的docker(1.2之前版本)中,有一个错误,如果它检测到已经分配了一个端口(甚至可能是系统,而不是docker运行,程序如nginx)即使你停止冲突,也会继续无法重新分配它,直到你重启docker。
检查没有其他人在使用该端口,然后重启docker。 (service docker.io restart)
答案 3 :(得分:2)
使用docker stop $(docker ps | grep ":PORT_NUMBER" | awk '{print $1}')
只需将端口号替换为运行Docker容器的端口即可。
例如:运行docker stop $(docker ps | grep ":8082" | awk '{print $1}')
将停止在端口8082上运行的容器
答案 4 :(得分:0)
对于Windows用户,请引用Docker documentation:
在Windows系统上,
CTRL+C
不会停止容器。因此,首先键入CTRL+C
以返回提示(或打开另一个shell),然后键入docker container ls
列出正在运行的容器,然后键入docker container stop <Container NAME or ID>
停止容器。否则,当您尝试重新运行容器时,会从守护程序收到错误响应。
此外,此命令还会停止所有正在运行的容器:
docker stop $(docker ps -q)
答案 5 :(得分:0)
停止以前的容器,终止该过程对我没有用。
起作用的是停止docker daemon并重新启动它。