I’m trying to run a Flask application and mysql database by running docker-compose up
on my computer. The flask is running on port 5000.
if __name__ == "__main__":
app.run(port=5000, debug=True)
The docker container is responding properly when I use docker exec
command. But I can't get any response from the host by using the url: http://localhost:5000
.
The curl -X GET <url>
command is giving the following output:
curl: (56) Recv failure: Connection reset by peer
The docker ps
command is giving the following output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bffa59c471f6 customer_transaction_app "/bin/sh -c 'python …" About an hour ago Up About an hour 0.0.0.0:5000->5000/tcp customer_transaction_app_1
ad60c2830ac0 mysql "docker-entrypoint.s…" About an hour ago Up About an hour 33060/tcp, 0.0.0.0:32001->3306/tcp customertransaction_db_host
Here is the Dockerfile:
FROM python:3.8 EXPOSE 5000 COPY requirements.txt /app/requirements.txt WORKDIR /app RUN pip install -r requirements.txt COPY . /app CMD python main.py
Here is the docker-compose.yml
file:
version: "2" services: app: build: ./ depends_on: - db ports: - "5000:5000" db: container_name: customertransaction_db_host image: mysql restart: always ports: - "32001:3306" volumes: - customertransaction-db-vol:/var/lib/mysql environment: MYSQL_ROOT_PASSWORD: 123456 MYSQL_DATABASE: customertransaction_db MYSQL_USER: user MYSQL_PASSWORD: 123456 volumes: customertransaction-db-vol: {}
Both the containers reside inside a docker network customer_transaction_default
. The docker network inspect
command creates the following output:
[ { "Name": "customer_transaction_default", "Id": "4b5b20f503af0026a2f1ef185436c9a8e3d9c2ece690e93ece0e6b12f7821edb", "Created": "2021-06-20T17:52:15.603679073+05:30", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "172.24.0.0/16", "Gateway": "172.24.0.1" } ] }, "Internal": false, "Attachable": false, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": false, "Containers": { "ad60c2830ac0f7e270daf03334ea8a8170200e92c2bc43492c378bd1d89cd3ac": { "Name": "customertransaction_db_host", "EndpointID": "de4597a1f58d711640f71a6169111f9842c7c5d74320825657a2518d07f36504", "MacAddress": "02:42:ac:18:00:02", "IPv4Address": "172.24.0.2/16", "IPv6Address": "" }, "bffa59c471f6762bb802fcee37db356cf2c7a59f4f88192e3546dd10ad9dbb2d": { "Name": "customer_transaction_app_1", "EndpointID": "a3ded03e28343921d799c0efc334034028821c231e1469d4359cd387c7f43f70", "MacAddress": "02:42:ac:18:00:03", "IPv4Address": "172.24.0.3/16", "IPv6Address": "" } }, "Options": {}, "Labels": {} } ]