1

If I have a super-dumb dockerfile, like this:

FROM ubuntu:latest
ENTRYPOINT echo

Is it possible to pass arguments to the ENTRYPOINT, so that it will print whatever argument I pass? I tried docker build -t test . && docker run test foo but I just got an empty line.

ewok
  • 20,148
  • 51
  • 149
  • 254
  • I would recommend a combination of arguments and/or environment variables, [as this SO answer outlines](https://stackoverflow.com/questions/19537645/get-environment-variable-value-in-dockerfile/34600106#34600106). You can specify default values if you like. Your `ENTRYPOINT` line should allow you to make use of an env var. – Eric McCormick Jan 30 '18 at 16:11
  • Is it possible to directly do the thing I'm asking about, or do I need to use a different solution? – ewok Jan 30 '18 at 16:12
  • I don't own the Dockerfile in question – ewok Jan 30 '18 at 16:12
  • 1
    If you can't edit the Dockerfile, you may wish to build a new Dockerfile off of the original one; assuming it's build specific. Otherwise you next best option may be to override the entrypoint during your docker run, such as `docker run --entrypoint=""`. Here's [the documentation from Docker](https://docs.docker.com/engine/reference/run/#entrypoint-default-command-to-execute-at-runtime). – Eric McCormick Jan 30 '18 at 16:15

1 Answers1

1

You can extend the image and fix the entrypoint:

FROM user_name/image_name
ENTRYPOINT ["echo"]

Or override the entrypoint:

docker run --entrypoint=echo user_name/image_name Hello World

Either way you don't need to be the owner of the Dockerfile you mention as long as you have access to the image.

Mike Doe
  • 16,349
  • 11
  • 65
  • 88