Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile entrypoint script arguments in docker run

My Dockerfile contains a

RUN xyz.sh --IP localhost

and when I give the command docker run I want to insert a new IP address:

docker run -it IP 127.0.0.1 name:tag

How to pass it like this?

I tried to give ENV in Docker file and using -e in run command but nothing works.


1 Answers

RUN instructions happen at build time.

ENTRYPOINT and CMD instructions happen at run time.

You probably want something like this in your Dockerfile:

....
ENTRYPOINT ["xyz.sh"]

CMD ["--IP", "127.0.0.1"]
....

Then you can run with:

docker run -it some-image --IP 127.0.0.1

Arguments after the image overwrite the CMD instruction so then it runs the ENTRYPOINT instruction followed by your arguments.

like image 67
johnharris85 Avatar answered Jul 01 '26 15:07

johnharris85