Search code examples
dockerdockerfileamazon-ecs

Passing arguments to Docker entry point


I'm having difficulty getting my docker image execute its entry point with the arguments I'm specifying.

In my docker file I have the following:

...
EXPOSE 8123
WORKDIR /bin_vts
VOLUME /bin_vts
ENTRYPOINT ["/bin_vts/vts", "$(hostname -I | awk '{print $1}')", "8123"]

I want my program to take as an argument the output of hostname -I | awk '{print $1}'(an ip address). I have tested this on my local machine and it works fine when I use /bin_vts/vts $(hostname -I | awk '{print $1}') 8123

However when I use this in docker my program tells me that I'm passing "$(hostname -I | awk '{print $1}')" instead of the expected ip address.

I'm not sure what I'm doing wrong. I've tried using a script but that says permission denied. This is getting deployed to ECS using Fargate and I tried it locally as well and in both places it fails.

Thanks!


Solution

  • Something like this should work:

    ENTRYPOINT ["/bin/bash", "/bin_vts/vts", "$(hostname -I | awk '{print $1}')", "8123"]
    

    The original entrypoint

    ENTRYPOINT ["/bin_vts/vts", "$(hostname -I | awk '{print $1}')", "8123"]
    

    is passing the literal argument $(hostname -I | awk '{print $1}') to vts. By using bash, you can evaluate the argument before passing it to vts.