skip to Main Content

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

2

Answers


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

    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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search