Skip to content

Instantly share code, notes, and snippets.

@piyushgarg-dev
Created October 21, 2023 10:00
Show Gist options
  • Save piyushgarg-dev/ea8c5aa52de0496753b88cd938abd728 to your computer and use it in GitHub Desktop.
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
Copy link

SufiyanGolandaz commented Jan 31, 2024

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

@srijoy-paul
Copy link

srijoy-paul commented Jun 17, 2024

Doing this also works fine, just perform the upgrade before install, and install the nodejs image:

`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" ]`

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