I have three components in my docker-compose, mysql db
, flask server
and react webapp
.
When I do request to the server in the chrome, it gives me:
OPTIONS http://server:5000/getTables net::ERR_CONNECTION_TIMED_OUT
But if I get into react container using docker exec -it
and then curl -X POST server:5000/getTables
, it works fine.
This is how I set up the cors in the flask app:
@app.route('/getTables', methods=['GET', 'POST', 'OPTIONS'])
@cross_origin(origin='*')
This is my docker-compose.yaml:
version: '3'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: 'TEST'
MYSQL_USER: 'xxx'
MYSQL_PASSWORD: 'xxx'
MYSQL_ROOT_PASSWORD: 'xxx'
ports:
- '3306:3306'
expose:
- '3306'
volumes:
- my-db:/var/lib/mysql
server:
build: ./flask
restart: on-failure
ports:
- '5000:5000'
expose:
- '5000'
volumes:
- ./flask:/server
web:
build: ./react
ports:
- 80:3000
volumes:
my-db:
This is the flask-server log:
server_1 | * Serving Flask app "app" (lazy loading)
server_1 | * Environment: production
server_1 | WARNING: This is a development server. Do not use it in a production deployment.
server_1 | Use a production WSGI server instead.
server_1 | * Debug mode: off
server_1 | * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
Is there anything wrong with my docker-compose file? Thank you in advance for the help!
EDIT It seems like an issue related to my react webapp container network setup. When I run the react app locally it works fine, but it will not connect to external API if I put it inside docker.