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
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.