简体   繁体   中英

Docker run entrypoint flags

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

If you can't extend 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.

EG:

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.

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 either:

  1. Creating a new image altogether with docker commit :

     $ docker run -d <image> 89373736 $ docker commit --change='ENTRYPOINT ["/bin/bash", "-l", "-c"]' 89373736 mynewimage
  2. Writing a custom Dockerfile:

     FROM <image> ENTRYPOINT ["/bin/bash", "-l", "-c"]

    and then build it:

     docker build -t mynewimage.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM