CMD, env variables & the -e arg

Hey people!
Probably I am stupid, but I am looking now for nearly 4 hours for a solution of my current problem. Maybe someone can help me here:
I created a Python-script which is able to download a file from an Object Store. It works like this:

  • user: $ python3 s3download.py <filename>

I wrote a Dockerfile with the content:

  • ADD s3download.py .
  • CMD [“sh”, “-c”, “python3”, “s3download.py”, "${files}]

After I created the image, I ran the container:

  • docker run -it -e files="<filename>" <imagename> /bin/bash

Sadly, it did not work, when I checked the folder. No files there. Still inside the container, I typed in (by hand):

  • python3 s3download.py $files

And it worked. So no problems with python3, the script oder env vars in general.

In the 4 hours of searching I found several structure ideas like:

  • CMD [“sh”, “-c”, "python3, “s3download.py ${files}”]
  • CMD [“sh”, “-c”, “python3 s3download.py ${files}”]
  • CMD [“sh”, “-c”, “python3”, “s3download.py”, “$files”]
  • CMD python3 s3download.py ${files}
  • CMD python3 s3download.py $files

And a million others. I tested all of them. None of these works.

The command sh -c needs one string as a parameter not three strings.

This should work: CMD ["sh", "-c", "python3 s3download.py ${files}"]

The following commands should also work:

(Tested with Docker 17.12.1-ce)