I already deploy my project with this docker config and it work for so long now i need to add more instance on AWS so I use every config the same as previous instance but there alert nginx 404 not found
I not sure what i do after deploy or not can't remember but my first instance still useful
this is my Dockerfile and my docker-compose.yml
docker-compose.yml
version: '3'
services:
flask:
build:
context: flask_application
dockerfile: Dockerfile
container_name: flask
image: myproject/test:latest
restart: unless-stopped
environment:
APP_ENV: "prod"
APP_DEBUG: "True"
APP_PORT: 5000
JWT_SECRET_KEY: test
MONGODB_DATABASE: flaskdb
MONGODB_USERNAME: mongodbuser
MONGODB_PASSWORD: password
MONGODB_HOSTNAME: mongodb
command: flask run --host=0.0.0.0 --port=5000
volumes:
- .:/src
depends_on:
- mongodb
networks:
- frontend
- backend
mongodb:
image: mongo:4.0.8
hostname: mongodb
container_name: mongodb
restart: unless-stopped
volumes:
- ./mongodb/mongod.conf:/etc/mongod.conf
- ./mongodb/initdb.d/:/docker-entrypoint-initdb.d/
- mongodbdata:/data/db
environment:
MONGODB_INITSCRIPTS_DIR: /docker-entrypoint-initdb.d
MONGO_INITDB_ROOT_USERNAME: mongodbuser
MONGO_INITDB_ROOT_PASSWORD: password
MONGO_INITDB_DATABASE: flaskdb
MONGODB_PORT_NUMBER: 27017
MONGODB_CLIENT_EXTRA_FLAGS: --authenticationDatabase=flaskdb
MONGODB_DATA_DIR: /data/db
MONDODB_LOG_DIR: /dev/null
networks:
- backend
command: ["-f", "/etc/mongod.conf"]
webserver:
build:
context: nginx
dockerfile: Dockerfile
image: digitalocean.com/webserver:latest
container_name: webserver
restart: unless-stopped
environment:
APP_ENV: "prod"
APP_NAME: "webserver"
APP_DEBUG: "true"
SERVICE_NAME: "webserver"
ports:
- "80:80"
- "443:443"
volumes:
- nginxdata:/var/log/nginx
depends_on:
- flask
networks:
- frontend
networks:
frontend:
driver: bridge
backend:
driver: bridge
volumes:
mongodbdata:
driver: local
appdata:
driver: local
nginxdata:
driver: local
flask Dockerfile
FROM ubuntu:20.04
RUN apt-get update -y \
&& apt-get install python3 -y \
&& apt-get install python3-pip -y
ENV FLASK_APP /var/www/wsgi.py
RUN mkdir /var/www/
WORKDIR /var/www/
COPY . /var/www/
RUN mkdir /var/www/apps/export
RUN python3 -m pip install --upgrade pip
RUN pip3 install -r requirements.txt
EXPOSE 5000
CMD flask run --host=0.0.0.0 --port=5000
nginx app.conf
upstream app_server {
server flask:5000;
}
server {
listen 80;
server_name _;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
client_max_body_size 64M;
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
gzip_static on;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_buffering off;
proxy_redirect off;
proxy_pass http://app_server;
}
}
nginx Dockerfile
FROM alpine:latest
RUN apk --update add nginx && \
ln -sf /dev/stdout /var/log/nginx/access.log && \
ln -sf /dev/stderr /var/log/nginx/error.log && \
mkdir /etc/nginx/sites-enabled/ && \
mkdir -p /run/nginx && \
rm -rf /etc/nginx/conf.d/default.conf && \
rm -rf /var/cache/apk/*
COPY conf.d/app.conf /etc/nginx/conf.d/app.conf
EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]