How can do something like:
docker exec -it 06a0076fb4c0 install-smt
But use the name of the container instead
docker exec -it container/container install-smt
I am running a build on CI server so I can not manually input the container ID.
How can I achieve this?
To run a command as a different user inside your container, add the --user flag: docker exec --user guest container-name whoami.
Description. The docker exec command runs a new command in a running container. The command started using docker exec only runs while the container's primary process ( PID 1 ) is running, and it is not restarted if the container is restarted. COMMAND will run in the default directory of the container.
Yes, you can do this by naming the container with --name
. Note that your command with container/container
is likely referencing an image name and not the container.
➜ ~ docker run --name my_nginx -p 80:80 -d nginx d122acc37d5bc2a5e03bdb836ca7b9c69670de79063db995bfd6f66b9addfcac ➜ ~ docker exec my_nginx hostname d122acc37d5b
Although it won't save any typing, you can do something like this if you want to use the image name instead of giving the container a name:
docker run debian docker exec -it `docker ps -q --filter ancestor=debian` bash
This will only work if you're only running one instance of the debian
image.
It does help if you're constantly amending the image when working on a new Dockerfile
, and wanting to repeatedly run the same command in each new container to check your changes worked as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With