Reputation: 4411
I am trying to run my flask application through Docker. I had it working last week, but now it is giving me some issues. I can start the server, but I can't seem to visit any content through my browser.
Here is my app.py
file (reduced):
... imports ...
app = Flask(__name__)
DATABASE = "users.db"
app.secret_key = os.environ["SECRET_KEY"]
app.config['UPLOAD_FOLDER'] = 'static/Content'
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
# For Dropbox
__TOKEN = os.environ["dbx_access_token"]
__dbx = None
... functions ...
if __name__ == '__main__':
app.run(port=5001, threaded=True, host=('0.0.0.0'))
Here is my Dockerfile
:
# Use an official Python runtime as a parent image
FROM python:3
# Set the working directory to /VOSW-2016-original
WORKDIR /VOSW-2016-original
# Copy the current directory contents into the container at /VOSW-2016-original
ADD . /VOSW-2016-original
# Putting a variables in the environment
ENV SECRET_KEY="XXXXXXXX"
ENV dbx_access_token="XXXXXXXX"
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 8000 available to the world outside this container
EXPOSE 8000
# Run app.py when the container launches
CMD ["python", "app.py", "--host=0.0.0.0"]
Here are the commands I am using to start the server:
docker build -t vosw_original ./VOSW-2016-original/
and then:
docker run -i -t -p 5001:8000 vosw_original
Then I get the message:
* Running on http://0.0.0.0:5001/ (Press CTRL+C to quit)
So the server seems to be running, but I can't seem to visit it when I do any of the following:
http://0.0.0.0:5001/
http://0.0.0.0:8000/
http://127.0.0.1:5001/
http://127.0.0.1:8000/
Where am I going wrong?
Upvotes: 1
Views: 5748
Reputation: 6144
You are running your app on the wrong port:
app.run(port=5001, threaded=True, host=('0.0.0.0'))
while exposing 8000. So by -p 5001:8000
you are mapping container's 8000 port (on which nothing is listening) to host's 5001 port. While your app is actually running on port 5001 within the container which is what the message is about.
Upvotes: 4