4 ms·
Is there a cleaner way to drop a user into a shell of a docker container with ports exposed instead of doing: services: web: entrypoint: /bin/bash
by nodesocket 7y ago
Is there a cleaner way to drop a user into a shell of a docker container with ports exposed instead of doing:
services:
web:
entrypoint: /bin/bash
And then:
docker-compose run --service-ports web
- yjftsjthsd-h 7y agodocker-compose exec?
- nodesocket 7y agoSo would just be: docker-compose exec web /bin/bash Saves having to add --service-ports
- castis 7y agoexec only works on specific running containers so you'll need the container id for this 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
- yjftsjthsd-h 7y agoYou only need to specify the container by ID if you're using docker directly; if you use docker-compose then you can use the service name and you don't need the `-ti`
- hasmolo 7y agoGenerally I use docker-compose exec <service> sh
- deleted 7y ago[deleted]
- e12e 7y agoI'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.