Docker Run fails for a Python Project
up vote
0
down vote
favorite
I have the following project structure for one of my Python project:
raspi-motion-detection
|-- project
|-- core
|-- motion_detector.py
|-- conf
|-- conf.json
I then have the following Dockerfile:
FROM jfloff/alpine-python
RUN mkdir -p /raspi_motion_detection/project
WORKDIR /raspi_motion_detection/project
COPY ./ $WORKDIR/
COPY ./requirements.txt $WORKDIR/
ADD . $WORKDIR
CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]
Building the image works fine, but when I tried to run it, I get the following error:
Joes-MacBook-Pro-78:project joe$ docker run joesan/dummy
python: can't open file '/raspi_motion_detection/project/core/motion_detector.py --conf /raspi_motion_detection/project/conf/conf.json': [Errno 2] No such file or directory
Joes-MacBook-Pro-78:project joe$
Any ideas as to what is happening? I did in fact ADD the WORKDIR to the Docker runtime, but still it would not find the necessary Python file.
python docker
add a comment |
up vote
0
down vote
favorite
I have the following project structure for one of my Python project:
raspi-motion-detection
|-- project
|-- core
|-- motion_detector.py
|-- conf
|-- conf.json
I then have the following Dockerfile:
FROM jfloff/alpine-python
RUN mkdir -p /raspi_motion_detection/project
WORKDIR /raspi_motion_detection/project
COPY ./ $WORKDIR/
COPY ./requirements.txt $WORKDIR/
ADD . $WORKDIR
CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]
Building the image works fine, but when I tried to run it, I get the following error:
Joes-MacBook-Pro-78:project joe$ docker run joesan/dummy
python: can't open file '/raspi_motion_detection/project/core/motion_detector.py --conf /raspi_motion_detection/project/conf/conf.json': [Errno 2] No such file or directory
Joes-MacBook-Pro-78:project joe$
Any ideas as to what is happening? I did in fact ADD the WORKDIR to the Docker runtime, but still it would not find the necessary Python file.
python docker
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have the following project structure for one of my Python project:
raspi-motion-detection
|-- project
|-- core
|-- motion_detector.py
|-- conf
|-- conf.json
I then have the following Dockerfile:
FROM jfloff/alpine-python
RUN mkdir -p /raspi_motion_detection/project
WORKDIR /raspi_motion_detection/project
COPY ./ $WORKDIR/
COPY ./requirements.txt $WORKDIR/
ADD . $WORKDIR
CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]
Building the image works fine, but when I tried to run it, I get the following error:
Joes-MacBook-Pro-78:project joe$ docker run joesan/dummy
python: can't open file '/raspi_motion_detection/project/core/motion_detector.py --conf /raspi_motion_detection/project/conf/conf.json': [Errno 2] No such file or directory
Joes-MacBook-Pro-78:project joe$
Any ideas as to what is happening? I did in fact ADD the WORKDIR to the Docker runtime, but still it would not find the necessary Python file.
python docker
I have the following project structure for one of my Python project:
raspi-motion-detection
|-- project
|-- core
|-- motion_detector.py
|-- conf
|-- conf.json
I then have the following Dockerfile:
FROM jfloff/alpine-python
RUN mkdir -p /raspi_motion_detection/project
WORKDIR /raspi_motion_detection/project
COPY ./ $WORKDIR/
COPY ./requirements.txt $WORKDIR/
ADD . $WORKDIR
CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]
Building the image works fine, but when I tried to run it, I get the following error:
Joes-MacBook-Pro-78:project joe$ docker run joesan/dummy
python: can't open file '/raspi_motion_detection/project/core/motion_detector.py --conf /raspi_motion_detection/project/conf/conf.json': [Errno 2] No such file or directory
Joes-MacBook-Pro-78:project joe$
Any ideas as to what is happening? I did in fact ADD the WORKDIR to the Docker runtime, but still it would not find the necessary Python file.
python docker
python docker
asked Nov 11 at 12:14
sparkr
4,9081240107
4,9081240107
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
In the last line of your Dockerfile:
CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]
When the container starts up it is trying to launch python
and pass it a single argument, which it interprets as the filename of a script to run. That argument, which is interpreted in its entirety as a script name, is /core/... conf/conf.json
. Since you don't have a single file with that name, spaces and options and all, Python fails.
If you're using the JSON-ish syntax you need to break each separate argument into its own "word":
CMD ["python", "core/motion_detector.py", "--conf", "conf/conf.json"]
(Note that the WORKDIR
directive globally changes the working directory for all subsequent commands, the default directory for COPY
and ADD
directives, and any ENTRYPOINT
and/or CMD
that eventually gets run. There's no $WORKDIR
variable you can reference, and I suspect variable expansion is actually causing files end up in the container root directory when you don't expect. Try just COPY ./ ./
to add content to the image.)
Cool! That worked! I understood what my mistake is!
– sparkr
Nov 11 at 12:38
add a comment |
up vote
0
down vote
Well you use fully qualified paths like they are relative.
Assuming that your Dockerfile is situated in the raspi-motion-detection
folder in your project structure...
CMD ["python", "/core/motion_detector.py", "--conf", "conf/conf.json"]
The /core...
part (note I broke all the command parts into separate items) will actually point to a location relative to the root folder as it starts with a '/' and it should actially look from here:
/raspi_motion_detection/project/project/core/motion_detector.py
the same goes for the conf/conf.json
that one will actually point to something relative to the WORKDIR. you might want to be more specific here too :-)
you can check your config by running something like:
docker run -it --rm your_image /bin/bash
and then look around how and what you actually added where with your build.
Your Dockerfile seems to be wrong on some points too
- You can not reference WORKDIR with $WORKDIR
- You copy a requirements.txt file but never run it so it will probably never do anything
- You see to copy the whole structure and dat will include the Dockerfile which is unnecessary
Hope it helps
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
In the last line of your Dockerfile:
CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]
When the container starts up it is trying to launch python
and pass it a single argument, which it interprets as the filename of a script to run. That argument, which is interpreted in its entirety as a script name, is /core/... conf/conf.json
. Since you don't have a single file with that name, spaces and options and all, Python fails.
If you're using the JSON-ish syntax you need to break each separate argument into its own "word":
CMD ["python", "core/motion_detector.py", "--conf", "conf/conf.json"]
(Note that the WORKDIR
directive globally changes the working directory for all subsequent commands, the default directory for COPY
and ADD
directives, and any ENTRYPOINT
and/or CMD
that eventually gets run. There's no $WORKDIR
variable you can reference, and I suspect variable expansion is actually causing files end up in the container root directory when you don't expect. Try just COPY ./ ./
to add content to the image.)
Cool! That worked! I understood what my mistake is!
– sparkr
Nov 11 at 12:38
add a comment |
up vote
2
down vote
accepted
In the last line of your Dockerfile:
CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]
When the container starts up it is trying to launch python
and pass it a single argument, which it interprets as the filename of a script to run. That argument, which is interpreted in its entirety as a script name, is /core/... conf/conf.json
. Since you don't have a single file with that name, spaces and options and all, Python fails.
If you're using the JSON-ish syntax you need to break each separate argument into its own "word":
CMD ["python", "core/motion_detector.py", "--conf", "conf/conf.json"]
(Note that the WORKDIR
directive globally changes the working directory for all subsequent commands, the default directory for COPY
and ADD
directives, and any ENTRYPOINT
and/or CMD
that eventually gets run. There's no $WORKDIR
variable you can reference, and I suspect variable expansion is actually causing files end up in the container root directory when you don't expect. Try just COPY ./ ./
to add content to the image.)
Cool! That worked! I understood what my mistake is!
– sparkr
Nov 11 at 12:38
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
In the last line of your Dockerfile:
CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]
When the container starts up it is trying to launch python
and pass it a single argument, which it interprets as the filename of a script to run. That argument, which is interpreted in its entirety as a script name, is /core/... conf/conf.json
. Since you don't have a single file with that name, spaces and options and all, Python fails.
If you're using the JSON-ish syntax you need to break each separate argument into its own "word":
CMD ["python", "core/motion_detector.py", "--conf", "conf/conf.json"]
(Note that the WORKDIR
directive globally changes the working directory for all subsequent commands, the default directory for COPY
and ADD
directives, and any ENTRYPOINT
and/or CMD
that eventually gets run. There's no $WORKDIR
variable you can reference, and I suspect variable expansion is actually causing files end up in the container root directory when you don't expect. Try just COPY ./ ./
to add content to the image.)
In the last line of your Dockerfile:
CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]
When the container starts up it is trying to launch python
and pass it a single argument, which it interprets as the filename of a script to run. That argument, which is interpreted in its entirety as a script name, is /core/... conf/conf.json
. Since you don't have a single file with that name, spaces and options and all, Python fails.
If you're using the JSON-ish syntax you need to break each separate argument into its own "word":
CMD ["python", "core/motion_detector.py", "--conf", "conf/conf.json"]
(Note that the WORKDIR
directive globally changes the working directory for all subsequent commands, the default directory for COPY
and ADD
directives, and any ENTRYPOINT
and/or CMD
that eventually gets run. There's no $WORKDIR
variable you can reference, and I suspect variable expansion is actually causing files end up in the container root directory when you don't expect. Try just COPY ./ ./
to add content to the image.)
answered Nov 11 at 12:31
David Maze
8,6082821
8,6082821
Cool! That worked! I understood what my mistake is!
– sparkr
Nov 11 at 12:38
add a comment |
Cool! That worked! I understood what my mistake is!
– sparkr
Nov 11 at 12:38
Cool! That worked! I understood what my mistake is!
– sparkr
Nov 11 at 12:38
Cool! That worked! I understood what my mistake is!
– sparkr
Nov 11 at 12:38
add a comment |
up vote
0
down vote
Well you use fully qualified paths like they are relative.
Assuming that your Dockerfile is situated in the raspi-motion-detection
folder in your project structure...
CMD ["python", "/core/motion_detector.py", "--conf", "conf/conf.json"]
The /core...
part (note I broke all the command parts into separate items) will actually point to a location relative to the root folder as it starts with a '/' and it should actially look from here:
/raspi_motion_detection/project/project/core/motion_detector.py
the same goes for the conf/conf.json
that one will actually point to something relative to the WORKDIR. you might want to be more specific here too :-)
you can check your config by running something like:
docker run -it --rm your_image /bin/bash
and then look around how and what you actually added where with your build.
Your Dockerfile seems to be wrong on some points too
- You can not reference WORKDIR with $WORKDIR
- You copy a requirements.txt file but never run it so it will probably never do anything
- You see to copy the whole structure and dat will include the Dockerfile which is unnecessary
Hope it helps
add a comment |
up vote
0
down vote
Well you use fully qualified paths like they are relative.
Assuming that your Dockerfile is situated in the raspi-motion-detection
folder in your project structure...
CMD ["python", "/core/motion_detector.py", "--conf", "conf/conf.json"]
The /core...
part (note I broke all the command parts into separate items) will actually point to a location relative to the root folder as it starts with a '/' and it should actially look from here:
/raspi_motion_detection/project/project/core/motion_detector.py
the same goes for the conf/conf.json
that one will actually point to something relative to the WORKDIR. you might want to be more specific here too :-)
you can check your config by running something like:
docker run -it --rm your_image /bin/bash
and then look around how and what you actually added where with your build.
Your Dockerfile seems to be wrong on some points too
- You can not reference WORKDIR with $WORKDIR
- You copy a requirements.txt file but never run it so it will probably never do anything
- You see to copy the whole structure and dat will include the Dockerfile which is unnecessary
Hope it helps
add a comment |
up vote
0
down vote
up vote
0
down vote
Well you use fully qualified paths like they are relative.
Assuming that your Dockerfile is situated in the raspi-motion-detection
folder in your project structure...
CMD ["python", "/core/motion_detector.py", "--conf", "conf/conf.json"]
The /core...
part (note I broke all the command parts into separate items) will actually point to a location relative to the root folder as it starts with a '/' and it should actially look from here:
/raspi_motion_detection/project/project/core/motion_detector.py
the same goes for the conf/conf.json
that one will actually point to something relative to the WORKDIR. you might want to be more specific here too :-)
you can check your config by running something like:
docker run -it --rm your_image /bin/bash
and then look around how and what you actually added where with your build.
Your Dockerfile seems to be wrong on some points too
- You can not reference WORKDIR with $WORKDIR
- You copy a requirements.txt file but never run it so it will probably never do anything
- You see to copy the whole structure and dat will include the Dockerfile which is unnecessary
Hope it helps
Well you use fully qualified paths like they are relative.
Assuming that your Dockerfile is situated in the raspi-motion-detection
folder in your project structure...
CMD ["python", "/core/motion_detector.py", "--conf", "conf/conf.json"]
The /core...
part (note I broke all the command parts into separate items) will actually point to a location relative to the root folder as it starts with a '/' and it should actially look from here:
/raspi_motion_detection/project/project/core/motion_detector.py
the same goes for the conf/conf.json
that one will actually point to something relative to the WORKDIR. you might want to be more specific here too :-)
you can check your config by running something like:
docker run -it --rm your_image /bin/bash
and then look around how and what you actually added where with your build.
Your Dockerfile seems to be wrong on some points too
- You can not reference WORKDIR with $WORKDIR
- You copy a requirements.txt file but never run it so it will probably never do anything
- You see to copy the whole structure and dat will include the Dockerfile which is unnecessary
Hope it helps
edited Nov 11 at 12:38
answered Nov 11 at 12:27
Ivonet
1,153518
1,153518
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248652%2fdocker-run-fails-for-a-python-project%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown