From 0a4e3619330325b96bc484edfd23843bf3648bbf Mon Sep 17 00:00:00 2001 From: Hamidreza Hassani Date: Tue, 21 Oct 2025 10:26:29 +0330 Subject: [PATCH 1/2] dockerize the project --- backend/.dockerignore | 1 + backend/Dockerfile | 14 ++++++++- docker-compose.yml | 73 ++++++++++++++++++++++++++++++++++++++++++- nginx/nginx.conf | 18 ++++++++++- 4 files changed, 103 insertions(+), 3 deletions(-) diff --git a/backend/.dockerignore b/backend/.dockerignore index e69de29..5d5c406 100644 --- a/backend/.dockerignore +++ b/backend/.dockerignore @@ -0,0 +1 @@ +./src/node_modules \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile index 3feaa5b..dac5591 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1 +1,13 @@ -# ADD DOCKERFILE CONTENTS HERE \ No newline at end of file +FROM node:22-slim + +WORKDIR /app + +COPY package*.json ./ + +RUN npm install + +COPY . . + +EXPOSE 3000 + +CMD ["npm", "start"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index db39ad0..722e787 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1 +1,72 @@ -# ADD DOCKER-COMPOSE CONTENT HERE \ No newline at end of file +volumes: + mongodb_data: + driver: local + redis_data: + driver: local + +networks: + techstach: + driver: bridge +services: + nginx: + container_name: techstach-nginx + image: nginx:stable-alpine + ports: + - 8088:80 + volumes: + - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf + networks: + - techstach + depends_on: + - db + - app + - redis + + app: + container_name: techstach-app + build: + context: ./backend + dockerfile: Dockerfile + ports: + - 3000:3000 + volumes: + - ./backend:/app + - /app/node_modules + networks: + - techstach + environment: + - MONGODB_URI=mongodb://db:27017/techstach + - REDIS_HOST=techstach-redis + - REDIS_PORT=6379 + - NODE_ENV=development + - PORT=3000 + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:3000/health"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 10s + depends_on: + - db + db: + container_name: techstach-mongodb + image: mongo:latest + environment: + MONGO_INITDB_ROOT_USERNAME: admin + MONGO_INITDB_ROOT_PASSWORD: admin + ports: + - 27017:27017 + networks: + - techstach + volumes: + - mongodb_data:/data/db + + redis: + container_name: techstach-redis + image: redis:alpine + ports: + - 6379:6379 + networks: + - techstach + volumes: + - redis_data:/data \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf index e4efe51..2be2f82 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1 +1,17 @@ -# ADD NGINX CONFIGS HERE \ No newline at end of file +server { + listen 80; + server_name localhost; + error_log /var/log/nginx/error.log; + access_log /var/log/nginx/access.log; + + location / { + proxy_pass http://app:3000; + proxy_http_version 1.1; + proxy_set_header Host $http_host; + proxy_set_header Scheme $scheme; + proxy_set_header SERVER_PORT $server_port; + proxy_set_header REMOTE_ADDR $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Upgrade $http_upgrade; + } +} \ No newline at end of file From d810d6b9aef339615354e421f83f35e7e9cf5b7e Mon Sep 17 00:00:00 2001 From: Hamidreza Hassani Date: Sun, 2 Nov 2025 18:58:38 +0330 Subject: [PATCH 2/2] add nginx image --- docker-compose.yml | 9 +++------ nginx/Dockerfile | 7 +++++++ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 nginx/Dockerfile diff --git a/docker-compose.yml b/docker-compose.yml index 722e787..8423e2f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,11 +10,11 @@ networks: services: nginx: container_name: techstach-nginx - image: nginx:stable-alpine + build: + context: ./nginx + dockerfile: Dockerfile ports: - 8088:80 - volumes: - - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf networks: - techstach depends_on: @@ -29,9 +29,6 @@ services: dockerfile: Dockerfile ports: - 3000:3000 - volumes: - - ./backend:/app - - /app/node_modules networks: - techstach environment: diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000..92618a5 --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,7 @@ +from nginx:stable-alpine + +COPY nginx.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file