From d9b4eb2e92a7a60396153fa78995434fcb323215 Mon Sep 17 00:00:00 2001 From: acyalcin Date: Sun, 6 Jul 2025 03:02:42 +0200 Subject: [PATCH] Fixed Dockerfile and docker-compose.yml --- .dockerignore | 7 +++++++ Dockerfile | 19 +++++++++++++++++++ app.js | 2 +- docker-compose.yml | 14 ++++---------- dockerfile | 8 -------- package.json | 4 +--- 6 files changed, 32 insertions(+), 22 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile delete mode 100644 dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..3adcd751 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +node_modules +npm-debug.log +Dockerfile +.dockerignore +.git +.gitignore +docker-compose.yml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..511d3651 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM node:24-alpine + +# Create app user and group +RUN addgroup app && adduser -S -G app app + +WORKDIR /usr/src/app + +# Copy package files and install dependencies as root +COPY package*.json ./ +RUN npm ci --omit=dev + +# Copy rest of the app +COPY . . + +# Switch to non-root user for runtime +USER app + +EXPOSE 3000 +CMD ["node", "app.js"] diff --git a/app.js b/app.js index d5b5db2f..974b2dd9 100644 --- a/app.js +++ b/app.js @@ -9,7 +9,7 @@ var express = require('express'); var app = express(); -app.set('port', process.env.PORT || 3005); // GİRİŞ PORTU AYARLANDI +app.set('port', process.env.PORT || 3000); // GİRİŞ PORTU AYARLANDI app.set('views', __dirname + '/app/server/views'); // VIEW KLASÖRÜ TANITILDI app.set('view engine', 'ejs'); // VIEW ENGINE AYARLANDI app.use(express.static(__dirname + '/app/public')); // KULLANICILAR TARAFINDAN ERİŞİLEBİLEN KLASÖR TANIMLANDI diff --git a/docker-compose.yml b/docker-compose.yml index a0965ac4..40c0bbf0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,8 @@ -version: '3.7' - services: - environment: - container_name: environment + app: + container_name: app build: context: . - dockerfile: dockerfile + dockerfile: Dockerfile ports: - - 3005:3005 - stdin_open: true - environment: - - CHOKIDAR_USEPOLLING=true - command: node app.js \ No newline at end of file + - "3000:3000" \ No newline at end of file diff --git a/dockerfile b/dockerfile deleted file mode 100644 index a585ae0f..00000000 --- a/dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM node:14.17.5 - -WORKDIR /app -COPY package.json ./ -RUN npm install -COPY . . -CMD ["node","app.js"] -EXPOSE 3005 \ No newline at end of file diff --git a/package.json b/package.json index 2bb53963..1931c6ab 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,7 @@ "description": "Sample Node.js Project", "main": "app.js", "scripts": { - "start": "node app.js", - "test": "echo \"Error: no test specified\" && exit 1", - "build": "echo 'Building the project...' && exit 0" // Replace this with your actual build command + "start": "node app.js" }, "author": "Adem Cemil YALCIN", "license": "ISC",