Reputation: 64
If I run
docker-compose ps
in my project I get a list of containers with Name, Command, State and Ports specified. Name looks like this:
prefix_real_container_name_1
If I use the full name to execute commands like:
docker-compose stop prefix_real_container_name_1
then I get an error:
No such service: prefix_real_container_name_1
But the following works:
docker-compose stop real_container_name
What is going on here?
Upvotes: 2
Views: 783
Reputation: 2254
Using docker-compose
to access your containers will always require to pass a service name as a parameter, currently no way to change that.
But you can use container_name
keyword in your compose file like this:
services:
random_service:
container_name: random_service
# other definitions
explicitly naming the container the same as your service name (like random_service
) so that it'll appear the same in docker ps
and docker-compose ps
and you'll be able to address it the same from:
$ docker stop random_service
and
docker-compose stop random_service
Upvotes: 2
Reputation: 19
Docker compose is adding some text pre- and postfixes to avoid collision with other containers name, like if you run two containers with node then without unique name them you and docker would have problems recognizing them
Upvotes: 0