Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does docker-compose exec only work on some services?

I have a docker-compose file specifying multiple services such as application, server, redis and database. When I want to access them I do docker-compose exec application bash or docker-compose exec server bash. But when I do a docker-compose exec redis sh I get the error ERROR: No such service: redis. I can however access it by doing docker exec -it smb-redis sh instead. What's the difference? Why can I access some of my running services, but not others using that command?

like image 275
Jonas Lomholdt Avatar asked Mar 08 '23 17:03

Jonas Lomholdt


1 Answers

service name and image name could be different. I could have a below docker-compose.yml

version: "3"
mysql:
  image: redis

And then to get into redis I will need to use

docker-compose exec mysql sh

So the service name matters and not what that service is actually running. The image name could be redis or mysql or anything else for that matter.

like image 100
Tarun Lalwani Avatar answered Mar 10 '23 09:03

Tarun Lalwani