diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..942162e25abae57e7131ffde302f2cbca5eea012 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +node_modules +Dockerfile +.dockerignore \ No newline at end of file diff --git a/.env b/.env new file mode 100644 index 0000000000000000000000000000000000000000..0e41d3ede26715adb50de5b0dfc43ed2ab544897 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +PORT = 3000 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1dcef2d9f2db74bf13c54f973f40239e00717423..b512c09d476623ff4bf8d0d63c29b784925dbdf8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -node_modules -.env \ No newline at end of file +node_modules \ No newline at end of file diff --git a/docker.compose.yaml b/docker.compose.yaml index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..bb647bd364ebcd6f22fc0e54cab085a04d65d387 100644 --- a/docker.compose.yaml +++ b/docker.compose.yaml @@ -0,0 +1,11 @@ +version: "3.8" +services: + app_server: + container_name: app_server + image: app_server:1.0.0 + build: + context: . + dockerfile: ./Dockerfile + command: npm run start + env_file: .env + ports: '3000:3000' \ No newline at end of file diff --git a/dockerfile b/dockerfile index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0ed8a67d13cabe436586875e36cfebd17bc3928b 100644 --- a/dockerfile +++ b/dockerfile @@ -0,0 +1,25 @@ +FROM node:18-alpine + +WORKDIR /app + +# Copy package.json and package-lock.json first (this leverages Docker cache for better efficiency) +COPY package.json . +COPY package-lock.json . + +# Install dependencies +RUN npm install + +# Copy the rest of the application code +COPY . . + +# Copy .env file if necessary for environment variables +COPY .env .env + +# Expose the application port +EXPOSE 3000 + +# Command to run the application +CMD ["npm", "start"] + +# Optionally, add a health check +# HEALTHCHECK CMD curl --fail http://localhost:3000/ || exit 1 diff --git a/index.js b/index.js index 59e23a25748b86f122cb107b86549ee7ea9ef288..caee80d6d2b1b66ed53562ee1259dc7d29c01f54 100644 --- a/index.js +++ b/index.js @@ -9,5 +9,5 @@ app.get('/', (req,res)=>{ }); app.listen(PORT, ()=>{ - console.log(`Listening to http://localhost:3001`); + console.log(`Listening to http://localhost:${PORT}`); }) \ No newline at end of file