Docker Community Forums

Share and learn in the Docker community.

CMD, env variables & the -e arg

(Mpijwinter) #1

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 <filename>

I wrote a Dockerfile with the content:

  • ADD .
  • CMD [“sh”, “-c”, “python3”, “”, "${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 $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, “ ${files}”]
  • CMD [“sh”, “-c”, “python3 ${files}”]
  • CMD [“sh”, “-c”, “python3”, “”, “$files”]
  • CMD python3 ${files}
  • CMD python3 $files

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

(Mikma) #2

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

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

The following commands should also work:

(Tested with Docker 17.12.1-ce)