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
?
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.
Stops containers and removes containers, networks, volumes, and images created by up .
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.
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.
you need to do "docker-compose up -d" then try ur commands
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With