4 ms·
I'm not sure what you're asking here - docker/docker-compose have both run and exec - they both start a process in a container. Run creates a new container, exe
by e12e 7y ago
I'm not sure what you're asking here - docker/docker-compose have both run and exec - they both start a process in a container. Run creates a new container, exec starts a process in a running container.
Both 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.