I've successfully built a Docker container and copied my application's files into the container in the Dockerfile. However, I am trying to execute a Python script that references an input file (that was copied into the container during the Docker build). I can't seem to figure out why my script is telling me it cannot locate the input file. I am including the Dockerfile I used to build the container below, and the relevant portion of the Python script that is looking for the input file it cannot find.
Dockerfile:
FROM alpine:latest
RUN mkdir myapplication
COPY . /myapplication
RUN apk add --update \
python \
py2-pip && \
adduser -D aws
WORKDIR /home/aws
RUN mkdir aws && \
pip install --upgrade pip && \
pip install awscli && \
pip install -q --upgrade pip && \
pip install -q --upgrade setuptools && \
pip install -q -r /myapplication/requirements.txt
CMD ["python", "/myapplication/script.py", "/myapplication/inputfile.txt"]
Relevant portion of the Python script:
if len(sys.argv) >= 2:
sys.exit('ERROR: Received 2 or more arguments. Expected 1: Input file name')
elif len(sys.argv) == 2:
try:
with open(sys.argv[1]) as f:
topics = f.readlines()
except Exception:
sys.exit('ERROR: Expected input file %s not found' % sys.argv[1])
else:
try:
with open('inputfile.txt') as f:
topics = f.readlines()
except:
sys.exit('ERROR: Default inputfile.txt not found. No alternate input file was provided')
Docker command on host resulting in error:
sudo docker run -it -v $HOME/.aws:/home/aws/.aws discursive python \
/discursive/index_twitter_stream.py
The error from the command above:
ERROR: Default inputfile.txt not found. No alternate input file was provided
The AWS stuff is drawn from a tutorial on how to pass your host's AWS credentials into the Docker container for use in interacting with AWS services. I used elements from here: https://github.com/jdrago999/aws-cli-on-CoreOS