Home > Software design >  Docker run entrypoint flags
Docker run entrypoint flags

Time:09-06

I have a base image I cannot modify in this case. The entrypoint of the image is python3, but I have a docker run in which I would like to make /bin/bash the entrypoint. The point is, I want to put the -c and -l flags in the /bin/bash command.

To clarify, I would like the equivalent of ENTRYPOINT ["/bin/bash", "-l", "-c"] but when I run the docker run --entrypoint /bin/bash <image> command

CodePudding user response:

If you can't to modify the image, you can achieve that by setting /bin/bash as the entrypoint and then passing the rest of the arguments as arguments to the container.

E.G:

docker run --entrypoint /bin/bash ubuntu -c ls

Runs ls inside your container. docker run does not accept sentences surrounded with quotes as it would try to find the executable named "/bin/bash -c -l" and would fail. So you're left with that or setting up a custom entrypoint script.

CodePudding user response:

If you're only looking to do this once, then you can override the entrypoint with the --entrypoint flag when using docker run.

$ docker run --entrypoint /bin/bash <image> -l -c

Everything that comes after the image name is passed to the new entrypoint as arguments.

Alternatively, if you expect you will be doing this again, I would instead recommend creating a new image altogether with docker commit:

$ docker run -d <image>
89373736
$ docker commit --change='ENTRYPOINT ["/bin/bash", "-l", "-c"]' 89373736 mynewimage

You will end up with a new image (mynewimage) that has the desired entrypoint.

CodePudding user response:

flag --entrypoint gets a string as input so the following command should work!

docker run --entrypoint "/bin/bash -l -c" <image>
  • Related