My code is in directory /test-scripts, details structure is as follows.
/test-scripts │___Dockerfile │ └───requirements.txt .... | └───IssueAnalyzer.py
Run the following command in directory /test-scripts.
/test-scripts(master)>
docker run --rm -p 5000:5000 --name testdockerscript testdockerscript:1.0 python3: can't open file '/testdocker/IssueAnalyzer.py -u $user -p $pwd': [Errno 2] No such file or directory
And my Dockerfile content is as follows.
FROM python:3.6-buster ENV PROJECT_DIR=/testdocker WORKDIR $PROJECT_DIR COPY requirements.txt $PROJECT_DIR/. RUN apt-get update && apt-get -yy install libmariadb-dev RUN pip3 install -r requirements.txt COPY . $PROJECT_DIR/. CMD ["python3", "/testdocker/IssueAnalyzer.py -u $user -p $pwd"]
Use $user, $pwd above to replace the real value in this question. In my opinion, the file IssueAnalyzer.py will be copy from current directory /test-scripts to /testdocker, but actually it is not. Please help to let me know how to change this Dockerfile. Thanks!
Advertisement
Answer
You have 2 different way to define the CMD: exec form and shell form.
You’re using the exec form but you’re not splitting the command correctly.
For this specific case, I suggest to use the shell form:
[...] CMD python3 /testdocker/IssueAnalyzer.py -u $user -p $pwd
If you really want to use the exec form:
[...] CMD ["python3", "/testdocker/IssueAnalyzer.py", "-u $user", "-p $pwd"]
Reference: https://docs.docker.com/engine/reference/builder/#cmd