0

I am trying to put a very simple Python API that returns some text and logs the timestamps of sent requests and what not. And if ran on the machine directly, it works fine, but when I try to use it in a Docker, I get no connection of any kind while trying to connect to 127.0.0.1 or localhost.

Here's the Dockerfile

FROM alpine
FROM python
FROM tiangolo/uwsgi-nginx-flask:python3.8
LABEL MAINTAINER="Asd <asd@asd.com"
COPY ./app /app
EXPOSE 5000


ENTRYPOINT ["python3", "/app/main.py"]

I run the container with

docker run --name unicorns -p 127.0.0.1:5000:5000 unicorn-image:latest

Thanks in Advance

EDIT1: Python code

# coding=utf8
import flask,json,sys,socket

import logging
log = logging.getLogger('werkzeug')
log.setLevel(logging.INFO)
logging.basicConfig(filename='./demo.log', level=logging.INFO)

from datetime import datetime


app = flask.Flask(__name__)
app.config["DEBUG"] = True

@app.route('/', methods=['GET'])


def home():
    test_date = datetime.now()
    app.logger.info('%s', json.dumps(test_date, indent=4, sort_keys=True, default=str))
    return "<h1>You are a unicorn!</h1>"

if __name__ == '__main__':
    app.run()
Adam
  • 43
  • 6
  • 2
    Can you share the docker container logs? Use this command: ```docker logs container_name``` – Kapil Khandelwal Jan 13 '21 at 09:08
  • docker logs aa83626dd578 * Serving Flask app "main" (lazy loading) * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: on * Serving Flask app "main" (lazy loading) * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: on – Adam Jan 13 '21 at 09:14
  • I've ran the container multiple times thats why it has 2 entries of the same thing – Adam Jan 13 '21 at 09:14
  • The logs look OK to me. Can you share minimal code to reproduce this issue. Or maybe the git repo of the source code (if possible). Thanks. – Kapil Khandelwal Jan 13 '21 at 09:21
  • try using `5000:5000` instead of `127.0.0.1:5000:5000` – kesarling He-Him Jan 13 '21 at 09:28
  • 1
    @Adam change `app.run()` to `app.run(host='0.0.0.0')`. – anemyte Jan 13 '21 at 09:28
  • 1
    @anemyte thank you very much! it fixed the problem and everything is working – Adam Jan 13 '21 at 09:37

0 Answers0