5

I am new to Docker.I have a script named ApiClient.py. The ApiClient.py script asks the user to input some data such as user's email,password,the input file(where the script will get some input information) and the output file(where the results will be output).I have used this Dockerfile:

FROM python:3
WORKDIR /Users/username/Desktop/Dockerfiles
ADD . /Users/username/Desktop/Dockerfiles
RUN pip install --trusted-host pypi.python.org -r requirements.txt
EXPOSE 80
ENV NAME var_name
CMD ["python", "ApiClient.py"]

1st Issue: I have used this WORKDIR and ADD because thats where the input and output files exist.Is it wrong to declare these directories?

2n Issue: The script asks for the user to input some info such as the email and password.However when i run:

docker run -p 4000:80 newapp

I get the following error: username = ("Please enter your username")

EOFError:EOF when reading a line

Why am i geting this error?

2 Answers 2

8

Use docker run -i -t <your-options>

So here, -i stands for interactive mode and -t will allocate a pseudo terminal for us.

Which in your scenario would be

docker run -p 4000:80 -it newapp

Hope it helps!

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

6 Comments

Thanks,i used: docker run -ti newapp and it worked. The probelm is that i cant define the input and the output file....
I see.. are you still getting the same error. You are not being able to username= interactively?
No i am not the error.Everything works when i enter my emal and username.The problem is that i dont know how to pass the input file as as argument from the container and where the output file will be created
@KonKyri, why not passing file paths as argument?
The file will be created inside container filesystem, the directory path you specify you can have it shared between container and host using -v host-dir:container-dir. These runtime arguments should work as well. But going with environment variables would be better for using your docker-file.
|
2

Lets make some necessary files as example

Dockerfile

FROM python
ADD . /python
WORKDIR /python

ENTRYPOINT ["python", "main.py"]

You want to run a script that will take two argument for input & output file

main.py

import sys
input_file = sys.argv[1]
output_file = sys.argv[2]
file = open(input_file, 'r') 
print(file.read())

file = open(output_file, 'w') 

file.write('Hello World')

Now build and run

$ docker build  -t test  .
$ docker run -it -v /tmp/python/:/python/data test data.txt data/output.txt

Your main.py will take input from /python/data.txt and write output in /python/data/output.txt

As /python/data is mounted into /tmp/python/, you will get output.txt in /tmp/python/ in your local

2 Comments

Thanks for your help.I still have a problem with the files though.I have a folder named newappfiles on my desktop which contains: Dockerfile,requirements.txt and main.py. I use the commands you mentioned while being in the newappfiles folder.Where should i put the data.txt(input) and the output.txt(output) files?Inside the newappfiles or some other place?Then when using the command: $ docker run -it -v /tmp/python/:/python/data test data.txt data/output.txt should I provide the full path of each file?
I can t understand where my input,output files will be.After the execution,the output.txt will be in the container?If yes,how will i access it?If no,where will it be in my computer?

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.