我正在尝试使用docker-compose编排多个容器。 为了排除故障,我经常通过以下操作最终从容器内运行bash:
$ docker-compose run --rm run web bash我总是尝试传递--rm开关,以便在退出bash会话时删除这些容器。 有时候,它们仍然存在,我在docker-compose ps的输出中看到它们。
Name Command State Ports ---------------------------------------------------------------------------------- project_nginx_1 /usr/sbin/nginx Exit 0 project_nginx_run_1 bash Up 80/tcp project_web_1 python manage.py runserver ... Exit 128 project_web_run_1 bash Up 8000/tcp在这一点上,我试图手动停止和删除这些组件,但我无法做到这一点。 我试过了:
$ docker-compose stop project_nginx_run_1 No such service: project_nginx_run_1我也尝试了其他命令rm , kill等。
我应该怎么做才能摆脱这些容器?
编辑:
修复了docker-compose ps的输出。
I'm trying to use docker-compose to orchestrate several containers. To troubleshoot, I frequently end up running bash from within a container by doing:
$ docker-compose run --rm run web bashI always try pass the --rm switch so that these containers are removed when I exit the bash session. Sometimes though, they remain, and I see them at the output of docker-compose ps.
Name Command State Ports ---------------------------------------------------------------------------------- project_nginx_1 /usr/sbin/nginx Exit 0 project_nginx_run_1 bash Up 80/tcp project_web_1 python manage.py runserver ... Exit 128 project_web_run_1 bash Up 8000/tcpAt this point, I am trying to stop and remove these components manually, but I can not manage to do this. I tried:
$ docker-compose stop project_nginx_run_1 No such service: project_nginx_run_1I also tried the other commands rm, kill, etc..
What should I do to get rid of these containers?
Edit:
Fixed the output of docker-compose ps.
最满意答案
只需使用docker stop命令停止这些测试容器,而不是使用docker-compose 。
docker-compose在启动多个容器时会发光,但使用docker-compose启动容器并不会阻止您使用docker命令执行任何需要使用单个容器的操作。
docker stop project_nginx_run_1 project_web_run_1此外,由于您正在调试容器,因此我建议使用docker-compose exec <service id> bash在正在运行的容器中获取一个shell。 这具有不启动新容器的优点。
just stop those test containers with the docker stop command instead of using docker-compose.
docker-compose shines when it comes to start together many containers, but using docker-compose to start containers does not prevent you from using the docker command to do whatever you need to do with individual containers.
docker stop project_nginx_run_1 project_web_run_1Also, since you are debugging containers, I suggest to use docker-compose exec <service id> bash to get a shell in a running container. This has the advantage of not starting a new container.
更多推荐
发布评论