Skip to content

Instantly share code, notes, and snippets.

@piyushgarg-dev
Created October 21, 2023 10:00
Show Gist options
  • Select an option

  • Save piyushgarg-dev/ea8c5aa52de0496753b88cd938abd728 to your computer and use it in GitHub Desktop.

Select an option

Save piyushgarg-dev/ea8c5aa52de0496753b88cd938abd728 to your computer and use it in GitHub Desktop.
Docker In One Shot
version: "3.8"
services:
postgres:
image: postgres # hub.docker.com
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_DB: review
POSTGRES_PASSWORD: password
redis:
image: redis
ports:
- "6379:6379"
FROM ubuntu
RUN apt-get update
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get upgrade -y
RUN apt-get install -y nodejs
COPY package.json package.json
COPY package-lock.json package-lock.json
COPY main.js main.js
RUN npm install
ENTRYPOINT [ "node", "main.js" ]
@SufiyanGolandaz

SufiyanGolandaz commented Jan 31, 2024

Copy link
Copy Markdown

while running above code in root directory, npm install will throw an error.

To solve this we can change the work directory:
e.g WORKDIR /usr/app

we can put this command before COPY commands
and it works fine
@piyushgarg-dev

@Krishna11118

Copy link
Copy Markdown

while running above code in root directory, npm install will throw an error.

To solve this we can change the work directory: e.g WORKDIR /usr/app

we can put this command before COPY commands and it works fine @piyushgarg-dev

Make sure you have added these commands:

RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get install -y nodejs

@nowshad-islam-dev

Copy link
Copy Markdown

Use this one for maximum efficient output with no error:
FROM ubuntu

Install dependencies

RUN apt-get update &&
apt-get install -y curl &&
curl -sL https://deb.nodesource.com/setup_18.x | bash - &&
apt-get install -y nodejs &&
apt-get upgrade -y &&
apt-get clean &&
rm -rf /var/lib/apt/lists/*

Set working directory

WORKDIR /app

Copy application files

COPY . .

Install node dependencies

RUN npm install

Set the default command

ENTRYPOINT ["node", "app.js"]

@Sk-muniruddin

Copy link
Copy Markdown

Use this one for maximum efficient output with no error:

1-----------------------------------------------------------------------------
FROM ubuntu

RUN apt-get update
RUN apt-get install -y curl
RUN apt-get upgrade -y

RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get install -y nodejs

COPY package.json package.json
COPY package-lock.json package-lock.json
COPY index.js index.js

RUN npm install
ENTRYPOINT [ "node","index.js" ]

   OR

2--------------------------------------------------
FROM node

COPY package.json package.json
COPY package-lock.json package-lock.json
COPY index.js index.js

RUN npm install
ENTRYPOINT [ "node","index.js" ]

@arsalanlal414

arsalanlal414 commented Jan 22, 2025

Copy link
Copy Markdown

This worked for me:

FROM ubuntu:latest

RUN apt-get update && apt-get install -y curl

RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get install -y nodejs

RUN node -v
RUN npm -v

COPY package.json package-lock.json ./

RUN npm install

COPY index.js .

EXPOSE 3000

CMD ["node", "index.js"]

@KunjShah95

Copy link
Copy Markdown

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["node", "main.js"]

these is the most simplest way through which u too can build a dockerfile as its in smaller in size instead of using ubuntu in docker file

@dharamdan01

Copy link
Copy Markdown

FROM ubuntu

Choose a base image (e.g., Ubuntu)

FROM ubuntu:22.04

RUN apt-get update && apt-get install -y curl gnupg
&& curl -sL https://deb.nodesource.com/setup_18.x | bash -
&& apt-get install -y nodejs
&& rm -rf /var/lib/apt/lists/*

COPY package.json package.json
COPY package-lock.json package-lock.json
COPY main.js main.js

RUN npm install

3. Fix ENTRYPOINT syntax (use square brackets and double quotes)

ENTRYPOINT ["node", "main.js"]

@quanghuynh10111-png

quanghuynh10111-png commented Feb 12, 2026

Copy link
Copy Markdown

ENTRYPOINT ["node", "app.js"]
ENTRYPOINT [ "node","index.js" ]
[]

@quanghuynh10111-png

quanghuynh10111-png commented Feb 12, 2026

Copy link
Copy Markdown

[] if iff fibonacill

@quanghuynh10111-png

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment