简体   繁体   English

docker-compose 运行现有容器

[英]docker-compose run existing container

I'm running an application under development with docker-compose.我正在使用 docker-compose 运行一个正在开发的应用程序。

I have a "web" service running a python Flask web application.我有一个运行 python Flask web 应用程序的“web”服务。 This service depends on other ones (database, cache, ...).此服务依赖于其他服务(数据库、缓存等)。

I need to run the "web" main service interactively in order to get access to a debugger (ipdb).我需要以交互方式运行“web”主服务才能访问调试器 (ipdb)。 I found out that the way to do this would be我发现这样做的方法是

docker-compose run --name my-app.web --service-ports web

When I exit this container and try to run it again with the same command I got this error:当我退出这个容器并尝试使用相同的命令再次运行它时,我收到了这个错误:

ERROR: Cannot create container for service web: Conflict. The container name "/my-app.web" is already in use by container "4fed84779bb02952dedb8493a65bd83b1a6664f066183233e8c8b4dc62291643". You have to remove (or rename) that container to be able to reuse that name.

How can I start again this container without creating a new one ?如何在不创建新容器的情况下重新启动此容器?

Or is it the correct way to create new containers each time I need to start this application ?还是每次需要启动此应用程序时创建新容器的正确方法?

Or did I miss something to be able to start one of the service interactively ?或者我是否错过了能够以交互方式启动其中一项服务的功能?

As you're setting a custom name, docker-compose run doesn't remove the container once the execution is completed.当您设置自定义名称时, docker-compose run在执行完成后不会删除容器。 To enable this behavior use the option --rm :要启用此行为,请使用选项--rm

docker-compose run --rm --name my-app.web --service-ports web

You can also remove the container manually to be able to run it again:您还可以手动删除容器以再次运行它:

docker rm my-app.web

This is not necessary if you don't set a custom name.如果您没有设置自定义名称,则不需要这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM