docker-compose run and exec: No container found

对着背影说爱祢 提交于 2020-07-15 11:38:08

问题


I was trying to open a second terminal un a docker with docker-compose.

First run the container with

docker-compose run my-centos bash

And when I try to open a second terminal

docker-compose exec my-centos bash

I get the message

ERROR:No container found for my_centos_1

If I search the name of running container I get

CONTAINER ID        IMAGE                                 COMMAND                  CREATED             STATUS                    PORTS                    NAMES
34a95b44f0a2        centos6   "bash"                   9 minutes ago       Up 9 minutes                                       docker_my-centos_run_1

why docker-compose exec search docker_my_centos_1 and not docker_my-centos_run_1?


回答1:


docker-compose is meant to run multi-container applications and is supposed to be used with docker-compose up. When you use docker-compose run, you make a special container that's not really meant for normal use.

Since docker-compose is just a wrapper around docker, you can still access this "specia" container via the normal docker command:

docker exec docker_my-centos_run_1 bash

Otherwise I'd suggest start you container with docker-compose up. This makes it so that you can run the second bash in the way that you specified:

docker-compose exec my-centos bash

Note: I don't know if you can attach a TTY directly with docker-compose up, so you might need to run an extra docker-compose exec my-centos bash to get two TTYs.




回答2:


you need to do "docker-compose up -d" then try ur commands



来源:https://stackoverflow.com/questions/47394428/docker-compose-run-and-exec-no-container-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!