Docker arguments work w/ COPY but not ADD

Question:

Got this solved!

I learned my smart quotes lesson the hard way…

Although, now that I know this- I find it crazy that Docker themselves used smart quotes in this tutorial: https://www.docker.com/blog/how-to-dockerize-your-python-applications/


Just want to figure this out for my edification..

Just learning Docker and getting a "Hello World" in Python working…

My Dockerfile:

# FROM python:3.11
# ADD main.py .
# CMD [“python”, “./main.py”]

FROM python:3.11
COPY main.py .
CMD ["python", "./main.py"]

Main.py

print("Hello World")

It works fine with COPY (as is), but when I build/run with ADD I get:

/bin/sh: 1: [“python”,: not found

What am I missing?

From what I understand, these should be doing the same thing…

Asked By: Casey Cushing

||

Answers:

It’s not the ADD or COPY causing this issue, it’s the two different CMD statements you’re using:

  • CMD [“python”, “./main.py”]
  • CMD ["python", "./main.py"]

Replace the smart quotes with normal quotes, and you should be good.

Answered By: Danielle M.
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.