Port Publishing When Running with Docker Compose
<p>I can't seem to work out a way to get port publishing to work with <code>docker-compose run</code> in the same way as I can with <code>docker run</code>.</p>

<p>Using Docker Compose (and therefore the port mapping in <code>docker-compose.yml</code>) gives a "Failed to connect" error from <code>curl</code>:</p>

<pre><code>$ docker-compose run flask
 * Running on http://0.0.0.0:2048/ (Press CTRL+C to quit)

$ curl http://localhost:2048/
curl: (7) Failed connect to localhost:2048; Connection refused
</code></pre>

<p>However, things are fine when manually passing the ports to <code>docker run</code>:</p>

<pre><code>$ docker run -p 2048:2048 --name flask -t flask_image
 * Running on http://0.0.0.0:2048/ (Press CTRL+C to quit)

$ curl http://localhost:2048
Hello World!
</code></pre>

<p>What am I missing?</p>

<hr>

<p><strong>Dockerfile</strong></p>

<pre><code>FROM centos:7

# Install EPEL repo.
RUN rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

# Install Python and Pip.
RUN yum -y update &amp;&amp; yum -y install \
    python \
    python-pip

# Flask is necessary to run the app.
RUN pip install flask

EXPOSE 2048

ADD hello_world_flask_app.py /src/hello_world_flask_app.py
CMD ["python", "/src/hello_world_flask_app.py"]
</code></pre>

<p><strong>hello_world_flask_app.py</strong></p>

<pre><code>from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=2048)
</code></pre>

<p><strong>docker-compose.yml</strong></p>

<pre><code>version: '2'
services:
  flask:
    build: .
    ports:
      - "2048:2048"
</code></pre>