Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Docker run command inside image

I have a simple docker command to start conatiner:

docker run -it --entrypoint /bin/bash image:v1.1
I want to execute some command like ls inside the docker container. I can do it by use the command above to go inside the container and run it. However, I want a single command to run the command outside the container, like:

docker run -it --entrypoint /bin/bash image:v1.1 --eval ls

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

docker exec doesn’t work in my case because the container isn’t keep running in the background.

I don’t know the exact syntax to add command to be executed into the docker run command. Can I get some help?Thanks!

>Solution :

You can do

docker run --rm --entrypoint /bin/bash image:v1.1 -c ls

I’ve removed the -it options since you’re no longer running the container interactively.

I’ve also added the --rm option to delete the container after it finishes. There’s no need to have it laying around after it finishes.

You also need to add the -c option to your bash command, so the full command run in the container becomes /bin/bash -c ls.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading