I can't seem to work out a way to get port publishing to work with docker-compose run
in the same way as I can with docker run
.
Using Docker Compose (and therefore the port mapping in docker-compose.yml
) gives a "Failed to connect" error from curl
:
$ 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
However, things are fine when manually passing the ports to docker run
:
$ 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!
What am I missing?
Dockerfile
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 && 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"]
hello_world_flask_app.py
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)
docker-compose.yml
version: '2'
services:
flask:
build: .
ports:
- "2048:2048"