Docker中无法正常结束容器的解决思路 - Docker cannot kill or stop container

Docker中无法正常结束容器的解决思路 - Docker cannot kill or stop container

步骤

  1. 查找无法删除的容器的ID:
# docker ps |grep "容器名" |awk -F' ' '{printf $1}'
b1beca5549ef
#
  1. 执行删除命令删除容器目录:
# ll /path_you_docker_install/containers | grep b1beca5549ef
drwx------. 5 root root 4096 41 17:10 b1beca5549ef455479681c05d0704959e44acb4fbacb1e340f203546c9c54b37
# rm -rf /path_you_docker_install/containers/b1beca5549ef455479681c05d0704959e44acb4fbacb1e340f203546c9c54b37

此时会有报错如下:

rm: 无法删除"/path_you_docker_install/containers/b1beca5549ef455479681c05d0704959e44acb4fbacb1e340f203546c9c54b37/secrets": 设备或资源忙
    无法删除"/path_you_docker_install/containers/b1beca5549ef455479681c05d0704959e44acb4fbacb1e340f203546c9c54b37/shm": 设备或资源忙
  1. 从上面报错我们可以看到“secrets”和“shm”共享挂载导致无法删除,首先找到挂载的位置,然后取消挂载后,再删除:
# cat /proc/mounts |grep "docker" |grep "b1beca5549ef"
  1. 取消挂载:
# umount /path_you_docker_install/containers/b1beca5549ef455479681c05d0704959e44acb4fbacb1e340f203546c9c54b37/secrets
# umount /path_you_docker_install/containers/b1beca5549ef455479681c05d0704959e44acb4fbacb1e340f203546c9c54b37/shm
  1. 再次查看:
# cat /proc/mounts |grep "docker" |grep "b1beca5549ef"

输出为空

  1. 现在删除容器目录就不会报错了
# rm -rf /path_you_docker_install/containers/b1beca5549ef455479681c05d0704959e44acb4fbacb1e340f203546c9c54b37

删除目录成功后,杀掉容器或者删除容器就都正常了

  1. 删除容器
 # docker kill b1beca5549ef
 # docker rm b1beca5549ef

完成以上步骤后,绝大多数问题都可以解决了。

附录

关于docker-compose 遇到 “ERROR: An HTTP request took too long to complete. Retry with --verbose to obtain debug information.”的报错,可以使用以上排查思路,但是要使用 --verbose来确认具体是哪一个容器的挂载出现了异常,具体使用方法为:

 # docker-compose --verbose ps
 # docker-compose --verbose down 
 # docker-compose --verbose up -d

会打印当前日志信息,如下:

compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('c7612844041a4569b37b2218134f9a6ff194af3bafccdf7d7593a0e4911e7334')
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.24/containers/c7612844041a4569b37b2218134f9a6ff194af3bafccdf7d7593a0e4911e7334/json HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': '',
'Args': ['-c', './StorageDumpService'],
'Config': {'ArgsEscaped': True,
           'AttachStderr': False,
           'AttachStdin': False,
           'AttachStdout': False,
           'Cmd': ['/bin/sh', '-c', './StorageDumpService'],
           'Domainname': '',
           'Entrypoint': None,
           'Env': ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/jre1.8/bin'],
...
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('483a9502f098381ea639a43b2cad946ec201df7f66c5030b1a7b92ddab026126')
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.24/containers/483a9502f098381ea639a43b2cad946ec201df7f66c5030b1a7b92ddab026126/json HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': '',
'Args': ['-server',
         '-Xms1024m',
         '-Xmx2048m',
         '-XX:PermSize=128M',
         '-XX:MaxPermSize=256M',
         '-Dh2.configdb.fileLocaltion=./db',
         '-Dlogs.home=./logs',
         '-Dlogging.config=./config/logback-spring.xml',
         '-Dspring.config.location=file:./config/',
...
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('43336976e7582a260b62339cca801104155c00fc92b1831c176ff259f1f5f327')

查看光标卡在了哪个容器,就是哪个容器出现了问题,以上,如有不对,还请各位订正。

你可能感兴趣的:(docker)