1

I got an issue I'm able to launch flask container but when I go in my browser I got " This site is inaccessible", my api is not loaded

docker-compose :

version: "3"

services:
  api:
    container_name: api
    build: ./api
    environment:
      - FLASK_APP=main.py
    command: flask run
    ports:
      - "5000:5000"

Dockerfile :

FROM python:3

# Install and setup flask
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY . .

EXPOSE 5000

UPDATE

basic app

from flask import Flask
app = Flask(__name__)

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

Result of docker-compose up --build enter image description here

When I go to localhost:5000 I got "This site is inaccessible"

I don't have access to my app in my browser but why ? I exposed port 5000 in dockerfile and map port 5000:5000

Thank's in advance

WHelp
  • 69
  • 1
  • 5
  • What's the image you attached; is that the response from a successful HTTP call? What is your host OS? Can you include enough application code to reproduce the issue, and include the plain-text logs from the container? – David Maze Jul 14 '20 at 12:05
  • 1
    Check if you are in the situation of running Flask on `127.0.0.1` and not on `0.0.0.0` like mentioned here: [Deploying a minimal flask app in docker - server connection issues](https://stackoverflow.com/a/30329547/1561148) – tgogos Jul 14 '20 at 12:26
  • @DavidMaze Thank you for your reply, OS is linux (ubuntu) Image is result of ```docker-compose up --build``` – WHelp Jul 14 '20 at 12:34
  • @tgogos Thank you for the link I will see it – WHelp Jul 14 '20 at 12:35
  • 1
    @tgogos Irun flask using command ``` flask run --host 0.0.0.0``` and it work's well. Thank you – WHelp Jul 14 '20 at 17:40

0 Answers0