Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated and optimised Dockerfile and modified dockerignore #1245

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
Expand Down
29 changes: 25 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,37 @@ FROM node:20-alpine

WORKDIR /app

COPY package*.json ./
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove this step, for docker optimisation we use multi copying technique, where we first copy dependency files (This creates a layer in image) and run the command for installing them (this creates another layer). Whenever changes are made to codebase which doesn't include changes with dependency files the first layer is cached and reused.

In our case it will be COPY package.json yarn.lock

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually if we do that the docker file will stop working i don't know what happens but if i install their then i get this error node modules not found

docker run -it -p 3000:3000 json-schema 
Usage Error: Couldn't find the node_modules state file - running an install might help (findPackageLocation)

$ yarn run [--inspect] [--inspect-brk] [-T,--top-level] [-B,--binaries-only] [--require #0] <scriptName> ...

RUN apk add --no-cache git curl bash && \
rm -f /usr/local/bin/yarn /usr/local/bin/yarnpkg && \
curl -o /tmp/yarn-4.4.0.tar.gz -L https://github.com/yarnpkg/berry/archive/refs/tags/@yarnpkg/cli/4.4.0.tar.gz && \
mkdir -p /opt/yarn && \
tar -xzf /tmp/yarn-4.4.0.tar.gz -C /opt/yarn --strip-components=1 && \
ln -s /opt/yarn/packages/yarnpkg-cli/bin/yarn.js /usr/local/bin/yarn && \
ln -s /opt/yarn/packages/yarnpkg-cli/bin/yarn.js /usr/local/bin/yarnpkg && \
rm -rf /tmp/yarn-4.4.0.tar.gz

COPY . .

RUN apk add --update git && \
git init && \
git submodule init && \
git submodule update && \
yarn
yarn install && \
yarn cache clean && \
rm -rf .git && \
rm -rf /root/.cache && \
rm -rf /root/.npm && \
rm -rf /root/.yarn && \
rm -rf /tmp/* && \
apk del git curl && \
rm -rf /var/cache/apk/*

COPY . .
RUN if [ ! -f .env ]; then \
cp .env.example .env && rm -rf .env.example; \
else \
rm -rf .env.example; \
fi
abhayymishraa marked this conversation as resolved.
Show resolved Hide resolved

EXPOSE 3000

CMD yarn dev
CMD ["yarn", "dev"]
Loading