I have been trying to create a flask app inside a docker container. The app works perfectly when run through the Flask development server, including access to the web pages from other machines on the network.
I have been trying to build a Docker container for the app. The problem is that I cannot access any web pages. I get 500 errors.
Some of my setup:
run.py
#!flask_v1/bin/python3
from app import app
app.run(debug=True, host='0.0.0.0')
Where flask_v1 is the virtualenv directory.
dockerfile
FROM python:3.4
COPY . /site
workdir /site
RUN pip install -r requirements.txt
ENV NAME sitename
CMD ["python", "./run.py"]
I removed EXPOSE 5000 from this version, but the same issues occurred with it present. It was originally placed under the pip line.
requirements.txt
click==6.7
CouchDB==1.1
docutils==0.14
Flask==0.12.2
Flask-CouchDB==0.2.1
flask-dynamo==0.1.2
Flask-Login==0.4.0
Flask-WTF==0.14.2
itsdangerous==0.24
Jinja2==2.9.6
jmespath==0.9.3
MarkupSafe==1.0
python-dateutil==2.6.1
PyYAML==3.12
s3transfer==0.1.11
six==1.11.0
Werkzeug==0.12.2
WTForms==2.1
Then I ran the build command as follows (with dockername replaced by an actual name):
docker build -t dockername .
Build completes and I run the image as follows:
docker run -p 5000:5000 dockername
Attempting to connect to the app at localhost:5000/index (the 'home' for the app), or just localhost:5000, or 127.0.0.1:5000/index, or [host_ip]:5000/index, or [container_ip]:5000/index all produced the same error:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1610, in full_dispatch_request
rv = self.preprocess_request()
File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1831, in preprocess_request
rv = func()
File "/usr/local/lib/python3.4/site-packages/flaskext/couchdb.py", line 154, in request_start
self.sync(current_app)
File "/usr/local/lib/python3.4/site-packages/flaskext/couchdb.py", line 131, in sync
if db_name not in server:
File "/usr/local/lib/python3.4/site-packages/couchdb/client.py", line 96, in __contains__
self.resource.head(name)
File "/usr/local/lib/python3.4/site-packages/couchdb/http.py", line 549, in head
return self._request('HEAD', path, headers=headers, **params)
File "/usr/local/lib/python3.4/site-packages/couchdb/http.py", line 581, in _request
credentials=self.credentials)
File "/usr/local/lib/python3.4/site-packages/couchdb/http.py", line 289, in request
conn = self.connection_pool.get(url)
File "/usr/local/lib/python3.4/site-packages/couchdb/http.py", line 507, in get
conn.connect()
File "/usr/local/lib/python3.4/http/client.py", line 871, in connect
self.timeout, self.source_address)
File "/usr/local/lib/python3.4/socket.py", line 516, in create_connection
raise err
File "/usr/local/lib/python3.4/socket.py", line 507, in create_connection
sock.connect(sa)
OSError: [Errno 99] Cannot assign requested address
After reading some other stackoverflow issues similar to this, I ran the container with the -d option and I accessed the container as follows:
docker exec -ti <container name> bash
Once inside, using curl and wget I attempted to access localhost:5000/index. Wget just threw 500 errors. Curl returns the Werkzeug page (see error dump above), including all of the html formatting. The directory structure looks fine
I know I must have something configured incorrectly. I just can't see what it is. The app works outside Docker and doesn't once in Docker. That I can't access the page from inside the container tells me something isn't right about the setup, but I'm either lacking the know how or having a "wood for the trees" moment. Please help a relative newbie.