Docker. Error: No se puede iniciar el contenedor: el puerto ya se ha asignado


Estoy trabajando con Docker y cuando creé un contenedor por primera vez, logré trabajar con él correctamente. Hoy reinicié mi computadora y me puse a trabajar con el contenedor Docker nuevamente.

Intenté "activar" el contenedor así:

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

Y este es el mensaje que recibo:{[10]]}

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

Así que traté de averiguar qué proceso está escuchando en el puerto 5000 y matarlo. Así:

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

También intenté reiniciar el servicio docker, como esto:

sudo service docker.io restart

Pero ninguna de estas cosas ha funcionado. Todavía recibo el mismo mensaje de error al intentar activar mi contenedor:

# 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

Buscando en Google una solución encontré que esto parece ser un problema conocido , pero tal vez usted puede ayudarme a encontrar una manera de salir de este problema.

ACTUALIZACIÓN:

Tal como lo solicitó @ Marcus Hughes, esta es la salida de 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  

Y si lo hago docker ps -a, esto es lo que obtengo:

$ 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
 31
Author: Xar, 2014-07-28

3 answers

De la salida docker ps, hay un contenedor que está escuchando en el puerto 5000 como se puede ver en la 0.0.0.0:5000->5000/tcp debajo de la columna ports.

Puedes matar este contenedor con docker kill container. En ese momento se liberará el puerto. En su caso:

docker kill 3fdfc9ecf30f
 34
Author: Marcus Hughes,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-03 20:39:46

Una razón por la que me he encontrado es que en algunas versiones de docker (pre 1.2), hay un error donde si detecta un puerto ya está asignado (tal vez incluso a un sistema, no docker ejecutar, programa como nginx) seguirá fallando para reasignarlo incluso si se detiene la cosa en conflicto, hasta que reinicie docker.

Compruebe que nada más está usando el puerto y, a continuación, reinicie docker. (servicio docker.io restart)

Referencia: https://github.com/docker/docker/issues/6476

 7
Author: Colin Coghill,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-10-15 03:36:43

Lo he arreglado reiniciando el servicio docker:

sudo service docker restart

Nota: Estoy usando Linux Mint, por cierto.

 6
Author: Pedro H,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-20 12:03:24