services:
web:
entrypoint: /bin/bash
And then: docker-compose run --service-ports web services:
web:
entrypoint: /bin/bash
And then: docker-compose run --service-ports web docker-compose exec <service> shBoth adhere to entrypoint and cmd; without arguments, entrypoint is called with cmd as argument (eg docker run ngnix would call the entry-script, which would call cmd - together they typically end up running nginx). If an argument is given, cmd is replaced. You would typically want that command to be bash: docker run ngnix bash / docker-compose run ngnix bash.
One difference is that docker-compose uses -ti (--tty/--interactive) by default, plain docker does not.
TL;DR to debug a service while it runs, start it like so:
docker-compose start web
And login to a shell in the container:
docker-compose exec web bash
(with ps you should now see your web server running next to your shell)
To run a shell inside a service, without starting the application itself:
docker-compose run --rm web bash
(your shell is now in a fresh container, your application typically won't be running (if there's no crazy entrypoint/init stuff going on) - and the container will be removed once you exit the shell.
docker-compose exec web /bin/bash
Saves having to add --service-ports
exec -ti f635776c2d08 /bin/bash
i do this often enough that i keep this in a makefile so i can do it by image name docker exec -ti `docker ps | grep 'container-name' | awk '{print $$1}'` /bin/bash