Docker IO Error with local js file
I am having hard time loading local js file with docker. I had no problem testing on local machine but if I host it on web server running on docker
No such file or directory: 'static/js/data.js error.
My code is organized as follow:
Root/ application.py static/ js/ data.js templates/ index.html
application.py I am generating the file
data.js and from
index.html I read the file
data.js with no problem
application.py I create a file using
file = open("static/js/data.js", "w+") which works fine in local machine but not in web server (EC2)
And here’s my dockerfile
FROM ubuntu:14.04 RUN apt-get update RUN apt-get install python-setuptools -y && DEBIAN_FRONTEND=noninteractive apt-get install python-setuptools -y RUN apt-get install python-pip -y RUN apt-get install python-numpy -y RUN apt-get install python-matplotlib -y RUN apt-get install python-mysqldb -y RUN apt-get install libpq-dev -y RUN apt-get install python-psycopg2 -y RUN apt-get install python-pandas -y RUN pip install flask ADD . /src # Expose EXPOSE 80 # Run CMD ["python", "/src/application.py"]
One Solution collect form web for “Docker IO Error with local js file”
The problem is that you didn’t specify an absolute link in your application.
You can easily reproduce this problem on your local by doing
cd / python /<pathtosrc>/src/application.py
Docker work directory is
/ by default.
So when you try to execute your program, it search for
/static/js/data.js. but it doesn’t exist.
You can solve the problem by using an absolute link, or by changing Docker work directory in your Dockerfile. Just add the following line at the end
# Run CMD ["python", "/src/application.py"] WORKDIR /src
WORKDIR will change the work directory for every command run after the