2

I'm starting with Docker. I have started with a Hello World script in Python 3. This is my Dockerfile:

FROM ubuntu:latest

RUN apt-get update
RUN apt-get install python3


COPY . hello.py


CMD python3 hello.py

In the same directory, I have this python script:

if __name__ == "__main__":
    print("Hello World!");

I have built the image with this command:

docker build -t home/ubuntu-python-hello .

So far, so good. But when I try to run the script with this command:

docker run home/ubuntu-python-hello

I get this error:

/usr/bin/python3: can't find '__main__' module in 'hello.py'

What am I doing wrong? Any advice or suggestion is accepted, I'm just a newbie.

Thanks.

3
  • 4
    try: COPY hello.py hello.py Commented Apr 11, 2015 at 17:34
  • Look like you copy current folder to folder hello.py (in docker container) Commented Apr 11, 2015 at 17:37
  • Thank you very much! I though that first argument was the target directory and the second the source! Post it as answer:) Commented Apr 11, 2015 at 17:39

2 Answers 2

2

Thanks to Gerrat, I solved it this way:

COPY hello.py hello.py

instead of

COPY . hello.py
Sign up to request clarification or add additional context in comments.

Comments

-1

You need to install python this way and confirm it with the -y.

RUN apt-get update && apt-get install python3-dev -y

1 Comment

You should really add some explanation as to why this should work - for instance, does the error point to the fact that python is not installed, to which this is a solution?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.