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:

  • Share host timezone with docker container
  • RunContainer: Error response from daemon: Duplicate mount point (Kubernetes)
  • How to use Nomad with Nvidia Docker?
  • How to start apache2 automatically in a ubuntu docker container?
  • boot2docker on windows - Can't access exposed port
  • error 7#7: *1 upstream prematurely closed connection while reading response header from upstream
  • Root/
      application.py
    
      static/
         js/
           data.js
    
      templates/
         index.html
    

    And in application.py I am generating the file data.js and from index.html I read the file data.js with no problem <script src="../static/js/data_data.js"></script>

    And in 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"]
    

  • Docker error link folder Read-only file system
  • How to use ebtables inside Docker?
  • docker-compose dosen't see node_modules from npm
  • Django - default port 0 instead of 3306 - Can't connect to MySQL server on '127.0.0.1' (61)
  • Docker within PCF - unable to connect to rabbitmq via AMQP (spring cloud bus)
  • Artifactory Professional License - NFS
  • 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
    

    Remember that WORKDIR will change the work directory for every command run after the WORKDIR line

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.