Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose run and exec: No container found

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?

like image 712
JuanPablo Avatar asked Nov 20 '17 14:11

JuanPablo


People also ask

What is docker compose exec?

docker-compose exec : will run docker exec to start a new process/command inside an existing, running container. docker-compose run : starts a new container for interactively executing the specified command, i.e. executing docker run.

Does docker compose down delete containers?

Stops containers and removes containers, networks, volumes, and images created by up .

How do I list a docker container?

In order to list the Docker containers, we can use the “docker ps” or “docker container ls” command. This command provides a variety of ways to list and filter all containers on a particular Docker engine.


2 Answers

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 special container via the normal docker command:

docker exec docker_my-centos_run_1 bash

Otherwise I'd suggest start your 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.

like image 77
Vinno97 Avatar answered Sep 21 '22 09:09

Vinno97


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

like image 28
farah Avatar answered Sep 19 '22 09:09

farah