NGINX Doesn't communicate with flask rest API. Docker
This should work:
docker-compose.yml
# Run docker-compose upversion: '3'services: nginx_demo: image: nginx:1.13.7-alpine container_name: nginx restart: always build: context: . dockerfile: ./Nginx/Dockerfile volumes: - ./Client/dist:/usr/share/nginx/html ports: - "80:80" depends_on: - flask_api links: - flask_api flask_api: container_name: flask_api restart: always build: context: . dockerfile: ./Server/Dockerfile volumes: - ./Server:/usr/src/app
Nginx/Dockerfile
FROM nginx:1.13.7-alpine# remove the old nginx.confRUN rm /etc/nginx/nginx.conf# Copy custom nginx configCOPY ./Nginx/nginx.conf /etc/nginx/nginx.confCOPY ./Client/dist /usr/share/nginx/htmlEXPOSE 80
Server/Dockerfile
FROM python:3.6-alpineADD ./Server /appWORKDIR /appRUN pip install -r requirements.txtEXPOSE 5000CMD ["python", "api.py"]
Nginx/nginx.conf
user nginx;worker_processes 1;error_log /var/log/nginx/error.log warn;pid /var/run/nginx.pid;events { worker_connections 1024;}http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; keepalive_timeout 65; gzip on; # Configuration for the server server { listen 80; location /api { proxy_pass http://flask_api:5000; } location / { root /usr/share/nginx/html; index index.html; expires -1; add_header Pragma "no-cache"; add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"; try_files $uri$args $uri$args/ $uri $uri/ =404; } }}