3

I am pretty new to Docker ( and all of the tools ). I am trying to setup a docker machine and container on my mac.

My container contains python web application powered by flask. I am running app with following statement

app.run(host='0.0.0.0', debug=True)

And this is what my docker-compose.yml looks like:

web:
  build: .                                                                                                                                                                                                
  ports:                                                                                                                                                                                                  
   - "5001:5001"                                                                                                                                                                                         
  volumes:                                                                                                                                                                                                
   - .:/volcode                                                                                                                                                                                          

When I try to load page hosted at 5001 (docker-machine-ip:5001), I don't see changes made to web application unless I do a

 docker-compose build && docker-compose up

UPDATE:

This is my Dockerfile:

FROM ubuntu:14.04
RUN apt-get -yqq update
RUN apt-get install -yqq python2.7
RUN apt-get install -yqq python-dev
RUN apt-get install -yqq libpq-dev
RUN apt-get install -yqq python-psycopg2
RUN apt-get install -yqq python-pip
ADD . /code
WORKDIR /code
RUN pip install -r server/requirements.txt
CMD python server/src/rest_server.py

Also this is equivalent to hot loading. (debug=True) should reload changed python files.

app.run(host='0.0.0.0', debug=True)

UPDATE 2:

Note that mount point in docker-compose.yml and Dockerfile are different. Having same mount points is resulting in the following error.

python: can't open file 'server/src/rest_server.py': [Errno 2] No such file or directory
user462455
  • 12,838
  • 18
  • 65
  • 96
  • Yeah, it should work, assuming all the directories are set up correctly. I don't think anyone can debug this without the Dockerfile, code and dir structure though. – Adrian Mouat Sep 13 '15 at 16:55
  • What sort of changes are you talking about. This worked for me. I had a python app based on flash which displays a string on the web page. I made the changes to the code to change the string and changes were reflected on the web page.. This is something related to Hot Loading and not every language supports this. eg:- You might have to restart the Tomcat server container to see the relevant changes. – Sachin Malhotra Sep 15 '15 at 08:36

1 Answers1

1

Since you are using machine, it is not possible to track the changes on your local file system. When you run docker-compose build && docker-compose up the content of your directory will be copied to the docker daemon inside the machine.

If you want to track your local changes, you have to run docker locally (which is not available to Mac users). But you can run a Linux vm with shared folders and a docker daemon running inside the vm, I guess.

This issue has been proposed to be an upcoming feature.

You can find another and longer answer here.

Community
  • 1
  • 1
Christian Smolka
  • 159
  • 1
  • 10