title: Can't access docker application from localhost using docker-compose
body: <p>before I start: I have searched this question already and implemented what the "Solutions" were and it did not help (setting host to 0.0.0.0). So, with that out of the way,</p>
  
  <p>Directory structure</p>
  
  <pre><code>|-- osr
  |    |-- __init__.py
  |-- requirements.txt
  |-- Dockerfile
  |-- docker-compose.yml
  </code></pre>
  
  <p>Dockerfile:</p>
  
  <pre><code>FROM python:3.7.5-buster
  
  EXPOSE 5000 # i have tried with and without this
  
  ENV INSTALL_PATH /osr
  ENV FLASK_APP osr
  ENV FLASK_ENV development
  RUN mkdir -p $INSTALL_PATH
  
  COPY requirements.txt requirements.txt
  RUN pip install -r requirements.txt
  
  COPY . .
  
  CMD [ "flask", "run", "--host=0.0.0.0"]
  </code></pre>
  
  <p>docker-compose.yml:</p>
  
  <pre><code>version: '3.8'
  services:
      web:
          build: .
          ports:
              - '5000:5000'
          expose:
              - '5000'
          volumes:
              - .:/osr
  </code></pre>
  
  <p>__ init __.py</p>
  
  <pre><code>import os
  from flask import Flask
  
  def create_app(test_config=None):
      app = Flask(__name__, instance_relative_config=True)
      app.config.from_mapping(
          SECRET_KEY='dev'
      )
  
      @app.route('/hello')
      def hello():
          return 'Hello, World!'
  
      return app
  </code></pre>
  
  <p>docker-compose build web
  docker-compose run web</p>
  
  <pre><code> * Serving Flask app "osr" (lazy loading)
   * Environment: development
   * Debug mode: on
   * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
   * Restarting with stat
   * Debugger is active!
   * Debugger PIN: 225-441-434
  </code></pre>
  
  <p>all of the below return "hmm can't reach this page"</p>
  
  <pre><code>http://localhost
  http://localhost:5000/hello
  http://127.0.0.1:5000/hello
  </code></pre>
  
  <p>I've even tried going to the containers IP with</p>
  
  <p>docker exec -it 49e677 bash
  ip add | grep global
      inet 172.21.0.2/16 brd 172.21.255.255 scope global eth0</p>
  
  <pre><code>http://127.21.0.2:5000/hello # nothing
  </code></pre>
  
  <p>Nothing.</p>
  
  <p>I'm sure the app itself works fine as I can simply run the app directly.</p>
  
  <pre><code>$env:FLASK_APP="osr"
  $env:FLASK_ENV="development"
  flask run --host=0.0.0.0
  </code></pre>
  
  <p>And it runs fine</p>
  
  <p><a href="https://i.stack.imgur.com/lBBPM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lBBPM.png" alt="localhost"></a></p>
  
  <p><strong>EDIT: UPDATE</strong></p>
  
  <p>I am actually able to get to the container when I run it through simply the Dockerfile... using </p>
  
  <p>docker run -it -p 5000:5000 osr_web # the container built by docker-compose build</p>
  
  <p>With this, I am able to access the endpoint through localhost:5000/hello</p>
  
  <p>So the issue appears to lie in spinning it up through docker-compose run</p>
  
  <p>Does this help at all?</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>I have discovered that when I run docker ps -a I can see that Docker run actually exposes the port, but docker-compose run does not:</p>
  
  <p><a href="https://i.stack.imgur.com/y4Xof.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y4Xof.png" alt="enter image description here"></a></p>