1

Reaching out for a bit of help/understanding of an issue I'm encountering while trying to point a flask application at a custom URL. Before this application was moved to a remote server and added to docker, it was being developed locally and could be accessed with: http://127.0.0.1:5000/.

A DNS entry was created for this custom URL. Trying to point the application at the URL results in: Cannot assign requested address. I've researched this error and haven't come across anything that helps me out in my situation.

Docker file:

FROM python:3.9-bullseye
ADD . /PIE
WORKDIR /PIE
RUN pip install -r requirements.txt
CMD ["python3", "app.py"]

Docker compose file:

version: "3"
services:
 app:
    build: .
    command: python app.py
    ports:
      - "5060:5060"
    volumes:
      - .:/PIE

Code snippet:

from flask import Flask, url_for, render_template, request, redirect, session
from flask_wtf.csrf import CSRFProtect
from data import dat_a

app = Flask(__name__)
app.register_blueprint(dat_a)
csrf = CSRFProtect(app)
csrf.init_app(app)

app = Flask(__name__)

@app.route('/', methods=['GET'])
def index():
    if session.get('logged_in'):
        return render_template('home.html')
    else:
        return render_template('index.html')

if __name__ == '__main__':
    app.secret_key = 'xxxx'
    app.run(debug=True, host='mysite.org', port=5060)

I have tried the following:

if __name__ == '__main__':
    app.secret_key = 'xxxx'
    app.config['SERVER_NAME'] = 'mysite.org'
    app.run()

============================================

if __name__ == '__main__':
    app.secret_key = 'xxxx'
    url = 'mysite.org:5060'
    app.config['SERVER_NAME'] = url
    app.run()

If I do something like:

if __name__ == '__main__':
    app.secret_key = 'xxxx'
    app.run(debug=True, host='localhost', port=5060)

It works just fine which makes me think the docker container is set only looking at the local side? I've also tried using gunicorn3 to create a WSGI server and push it out of a development server.

Environment:

  • Nginx for a proxy manager
  • Docker installed on a remote server (using portainer as a gui interface)
Invisible
  • 13
  • 4
  • Does changing `host='0.0.0.0'` work? Also see [Deploying a minimal flask app in docker - server connection issues](https://stackoverflow.com/questions/30323224/deploying-a-minimal-flask-app-in-docker-server-connection-issues); in general, if your application only listens on the container-private localhost interface, it will be unreachable from outside its container. – David Maze May 11 '22 at 17:07
  • @DavidMaze ```host='0.0.0.0'``` does work. I experimented with it yesterday but just realized after reading your comment where I was going wrong. Thank you! – Invisible May 11 '22 at 17:32

0 Answers0