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:

  • Using Spinnaker to deploy a Docker image from dockerhub to Aws Eb
  • Coreos security
  • How to install dependencies via Composer for Symfony project in Dockerfile?
  • How to get the Docker version using the Remote API
  • Why is this refresh token request to returning a 404?
  • Using docker-compose to start web and backend. How can I get the IP of backend from web?
  • Root/

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

  • Root user in Elasticsearch 2.4.0 in Docker container
  • Flask-WTF CSRF validation fails when app moved to docker production environment
  • getting bundler load error frequently and no such file Gemfile error
  • Why do we need run update before run install in Dockerfile?
  • Multiple static IPs for Docker containers
  • Consul and Tomcat in the same docker container
  • 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/

    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/"]
    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.