如何用`docker

编程入门 行业动态 更新时间:2024-10-25 00:24:29
如何用`docker-compose run`阻止容器运行(How stop containers run with `docker-compose run`)

我正在尝试使用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 bash

I 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/tcp

At 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_1

I 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_1

Also, 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.

更多推荐

本文发布于:2023-08-05 19:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1438362.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何用   docker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!