1
votes

I am running Flask application in Python using docker-compose. I am able to run the Flask app using 5000 port. I am trying to run it on 6000 besides another Flask app running on 5000. But I am unable run it on 6000 port. Any help would be appreciated.

docker-compose.yml

version: '3.8'
services:
  web:
    build: ./web
    ports:
      - "6000:5000"

app.py

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)

Dockerfile:

FROM python:3
COPY . /app
WORKDIR /app
RUN pip install -U pip
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["app.py"]

requirements.txt

Flask==1.1.1

Port 6000 is listening. I am able to get a connection succeeded by executing nc command with host and port.

I am unable to run the app on port 6000.

I got the following when I hit http://#{HOST_IP}:6000 in browser

This site can’t be reached
The web page at http://#{HOST_IP}:6000/ might be temporarily down or it may have moved permanently to a new web address.
2
what do the docker logs say ? does the server start ? - Cptmaxon
Yes. server gets started. Docker logs says "Running on 0.0.0.0:5000" - Galet
what do you mean by I am trying to run it on 6000 besides another Flask app running on 5000? Do you run the same application in a different container, the same container? Please share the sequence of commands that can be rerun to reproduce the issue you face - rok
according to your docker logs @Galet your flask application is running on http://#{HOST_IP}:5000/ - M_x
@rok Yes. I am running the same flask app on 5000 and 6000 in different containers. - Galet

2 Answers

3
votes

6000 is unsafe port that is why browser not allowing to access the application.

how-to-fix-err-unsafe-port-error-on-chrome-when-browsing-to-unsafe-ports

But you should not allow this port, just try to publish another port.

version: '3.8'
services:
  web:
    build: ./web
    ports:
      - "5001:5000"

For downvoter

enter image description here

Here is Github Repo to verify this

git clone https://github.com/Adiii717/dockerize-flask-app.git
cd dockerize-flask-app/
# this will not work in the browser
PORT=6000 docker-compose up
1
votes

You haven't defined any routes. The app server has no idea what routes are available nor does it know what you want to return, so you need to specify that.

Here's a more complete version of app.py

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)

Please refer to the Flask tutorial for a minimal app.