Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 5956

Flask Docker container not acecssible via Browser on Ubuntu

$
0
0

I created a simple flask API that I am deploying via docker. When I try to run it locally on my Ubuntu machine, the container runs but I cannot access any endpoint associated with the container.

api.py

from flask import Flask, jsonify, request, send_file, make_responseimport requestsimport jsonimport psycopg2 as pgimport sqlalchemy as sqlfrom flask_cors import CORSimport datetime as dtimport pandas as pdimport mathimport osimport re#own filesimport support as supimport sql as ssqlapp = Flask(__name__)CORS(app)@app.route("/products", methods=["GET"])def get_products()    return {"Hello":"World"}

The api files itself contain no further instructions like "app.run()" or anything like that. Running Flask locally works. Deploying to our k8s cluster works too. It is just on the local ubuntu machine (Ubuntu 22.04) that I cannot access the container. For 127.0.0.1:5000/products, 0.0.0.0:5000/products and localhost:5000/products it throws a "This site can’t be reached" error

DOCKERFILE

FROM python:3.9-slimWORKDIR /appCOPY . /appRUN apt update && apt upgrade -yRUN apt install -y libpq-devRUN pip install psycopg2-binaryRUN pip install -r requirements.txtRUN apt-get install texlive-latex-base texlive-latex-extra texlive-fonts-recommended texlive-science -yEXPOSE 5000CMD ["flask", "--app", "api", "run", "--host","0.0.0.0", "--debug"]

docker commands

sudo docker build -t api-test .sudo docker run -p 5000:5000 api-test

docker output

* Serving Flask app 'api' * Debug mode: onWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on all addresses (0.0.0.0) * Running on http://127.0.0.1:5000 * Running on http://172.17.0.2:5000Press CTRL+C to quit * Restarting with stat * Debugger is active! * Debugger PIN: 114-686-213

I have looked through a lot of of posts detailing this very same issue. Most solutions are connected to the "--host","0.0.0.0" line or portmapping, both of which is given here.

Anyother ideas what could be happening?


Viewing all articles
Browse latest Browse all 5956

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>