From 3fb2a522eac4c655c12d30ea6a895333877f7f32 Mon Sep 17 00:00:00 2001 From: Irwan Cahyono Date: Thu, 7 Aug 2025 10:06:51 +0700 Subject: [PATCH] docker nginx --- .dockerignore | 12 ++++++++++++ Dockerfile | 18 ++++++++---------- docker-compose.yml | 2 +- nginx.conf | 11 +++++++++++ 4 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 .dockerignore create mode 100644 nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ad063c6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +node_modules +.dockerignore +.git +.gitignore +.vscode +.env +*.log +*.md +Dockerfile +README.md +nuxt.config.ts +tsconfig.json diff --git a/Dockerfile b/Dockerfile index 41b029b..935693b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# Tahap build +# Dockerfile untuk SPA Nuxt 3 FROM node:24-alpine AS builder WORKDIR /app @@ -10,15 +10,13 @@ COPY . . RUN npm run build -# Tahap production -FROM node:24-alpine AS runner +# Gunakan NGINX untuk menyajikan SPA +FROM nginx:1.29.0-alpine-slim -WORKDIR /app +# Salin hasil build ke folder root nginx +COPY --from=builder /app/.output/public /usr/share/nginx/html -RUN npm install -g serve +# Salin konfigurasi khusus NGINX untuk SPA (opsional tapi direkomendasikan) +COPY nginx.conf /etc/nginx/conf.d/default.conf -COPY --from=builder /app/.output/public ./public - -EXPOSE 3000 - -CMD ["serve", "-s", "public", "-l", "3000"] \ No newline at end of file +EXPOSE 80 diff --git a/docker-compose.yml b/docker-compose.yml index c5695f4..15447d3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ services: build: . container_name: nuxt-container ports: - - "3000:3000" + - "3000:80" env_file: - .env environment: diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..cbb6356 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,11 @@ +server { + listen 80; + server_name localhost; + + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } +}