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:

  • Docker in production
  • Can't delete mysql database, table or even alter table inside docker
  • Build a multi node Kafka cluster on docker swarm
  • Which tag of Ruby Docker image should I use?
  • How to debug Golang application in Docker with VSCode?
  • Starting multiple services inside Docker container
  • 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/"]

  • How do I make a Docker container start automatically on system boot?
  • Docker swarm constantly shuts down containers
  • How to install ffmpeg for ubuntu using command line?
  • Docker backups from host vs data volume containers?
  • error starting docker daemon on ubuntu 14.04 (Devices cgroup isn't mounted)
  • Why docker sleep 1 for continuous background process?
  • 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.