-1

I'm using CentOS.7 in a container (because I have to) and need to install some RedHat Software Collection packages to up-version a couple of tools. This involves running source scl_source enable <package> to set up the environment, which I'm doing using an ENTRYPOINT script. Here's what I have in my Dockerfile, and it works...

ENV ENTRYPOINT="/usr/bin/entrypoint.sh"
RUN echo "#!/bin/bash" > ${ENTRYPOINT}; \
    chmod +x ${ENTRYPOINT}

# we need later Git for Visual Studio Code
RUN yum -y install rh-git227; \
    echo "source scl_source enable rh-git227" >> ${ENTRYPOINT}

# we need later python for Visual Studio Code
RUN yum -y install rh-python38-python-devel; \
    echo "source scl_source enable rh-python38" >> ${ENTRYPOINT}

# finish off the extrypoint script to run whatever needs running
RUN echo 'env|sort' >> ${ENTRYPOINT}; \
    echo 'echo ARGV="$@"' >> ${ENTRYPOINT}; \
    echo 'exec "$@"' >> ${ENTRYPOINT}
ENTRYPOINT [ "/usr/bin/entrypoint.sh" ]

When I start the container using docker run -it container /bin/bash --login then the entrypoint.sh script is run and is passed the original command line (/bin/bash --login). All good.

However, it bugs me having to repeat the script name in the ENTRYPOINT command, but doing something "obvious" like ENTRYPOINT [ ${ENTRYPOINT} ] doesn't work, even if I change ENV to ARG in the definition. It appears to me that Docker requires a literal string in ENTRYPOINT [...].

I also tried ENTRYPOINT [ "/bin/sh", "-c", ${ENTRYPOINT} ] using ENV but using this form doesn't pass the command line through from docker run. Any suggestions?

6
  • 1
    Does this answer your question? Docker ENTRYPOINT shell form with parameters Commented Jan 20, 2023 at 10:30
  • Please check if this helps: stackoverflow.com/questions/67484814/… Commented Jan 20, 2023 at 10:40
  • I'd just get rid of the ENTRYPOINT environment variable. You might find this easier to write and maintain if you COPY the script from the host system into the image, instead of building it up line by line using RUN echo commands, and this will also limit the number of times you need to repeat the filename. Commented Jan 20, 2023 at 12:51
  • @Paolo yes, given the lack of a usable Dockerfile variable, using the shell form of ENTRYPOINT to expand the environment variable and pass in the CMD array is a very readable workaround. Thanks. Commented Jan 20, 2023 at 14:31
  • @MikeMozhaev no, that answer doesn't help, but thanks for trying. Commented Jan 20, 2023 at 14:33

1 Answer 1

2

The answer is to use "shell" form

ENTRYPOINT ${ENTRYPOINT} "$0" "$@"

which Docker converts to "array" form

ENTRYPOINT [ "/bin/sh", "-c", "${ENTRYPOINT} \"$0\" \"$@\"" ]

The shell substitutes $0 and $@ for the parameters appearing after the command_string, which are the contents of the Dockerfile CMD array (or the parameters passed to docker run, which override this).

See https://stackoverflow.com/a/75063327/232452 for a full explanation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.