From 40ed6fa9eccba7422e3ad543923d58c3de794fe6 Mon Sep 17 00:00:00 2001 From: Hyunggyu Jang Date: Wed, 22 Mar 2023 22:59:29 +0900 Subject: [PATCH] Provide nginx docker build recipe --- Dockerfile | 8 ++++++++ client/nginx.conf | 15 +++++++++++++++ docker-compose.yml | 15 ++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 client/nginx.conf diff --git a/Dockerfile b/Dockerfile index f1dc95b254..ce95f49f45 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,3 +25,11 @@ EXPOSE 3080 ENV HOST=0.0.0.0 # Run the app when the container launches CMD ["npm", "start"] + +# Optional: for client with nginx routing +FROM nginx:stable-alpine AS nginx-client +WORKDIR /usr/share/nginx/html +COPY --from=react-client /client/public /usr/share/nginx/html +# Add your nginx.conf +COPY /client/nginx.conf /etc/nginx/conf.d/default.conf +ENTRYPOINT ["nginx", "-g", "daemon off;"] diff --git a/client/nginx.conf b/client/nginx.conf new file mode 100644 index 0000000000..1924aded1e --- /dev/null +++ b/client/nginx.conf @@ -0,0 +1,15 @@ +server { + listen 80; + server_name localhost; + + location / { + # Serve your React app + root /usr/share/nginx/html; + index index.html; + } + + location /api { + # Proxy requests to the API service + proxy_pass http://api:3080/api; + } +} diff --git a/docker-compose.yml b/docker-compose.yml index 6d452f0f32..3c1b061638 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,21 @@ version: "3.4" services: + # client: + # image: react-client + # build: + # context: . + # target: nginx-client + # restart: always + # ports: + # - 3080:80 + # volumes: + # - /client/node_modules + # depends_on: + # - api api: ports: - - 3080:3080 + - 3080:3080 # Change it to 9000:3080 if you want to use nginx depends_on: - mongodb image: node-api @@ -18,6 +30,7 @@ services: - NODE_ENV=production - MONGO_URI=mongodb://mongodb:27017/chatgpt-clone volumes: + - /client/node_modules - ./api:/api - /api/node_modules mongodb: