1

I have below requirement to create a dockerfile.

My image is all about downloading 2 zip files. I want these zip file to be downloaded as per condition as follows.

if ($arg == "xxx")
    'download this A.zip'
else if ($arg == "zzz") 
    'download this B.zip'
else 
    'download A.zip and B.zip'

Now, someone who pulls such Docker image, appropriate zip file should get downloaded based the argument passed.

How to go about?

Rot-man
  • 18,045
  • 12
  • 118
  • 124
  • 2
    Possible duplicate of [Dockerfile if else condition with external arguments](https://stackoverflow.com/questions/43654656/dockerfile-if-else-condition-with-external-arguments) – David Maze Mar 26 '19 at 11:48
  • 1
    If someone pulls an image, they'll get a fixed binary, which will have one program or the other. Maybe you want multiple images, one for each variant? Or if the zip files are actually data, distribute them separately from the image and use `docker run -v` to inject them? – David Maze Mar 26 '19 at 11:49
  • Agree with David, this looks more appropriate for using image tags. Otherwise someone will need to pull an image with both zip files and use runtime logic to select which to use. – BMitch Mar 26 '19 at 19:56

2 Answers2

1

You can utilize ARG command and --build-arg flag when building an image. And then you can do your ifs like this:

FROM debian
ARG X
RUN /bin/bash -c "if [ '${X}' == 'x' ]; then echo 'A'; else echo 'B'; fi"

And docker build --build-arg X=x .

Karol Samborski
  • 2,757
  • 1
  • 11
  • 18
0

create docker image with both A.zip and B.zip and set shell script for CMD for docker image. Allow users to pass environment variable at run time and this shell script can capture the ENV value and act accordingly.

Akash Sharma
  • 721
  • 3
  • 6