Exercise:
- Build a docker image for the following repo
- Manual steps:
- Ensure node js and npm are installed
- execute
npm install this will install dependencies
- execute
npm run build which generates a folder called dist
- execute
npm run preview this should run the application
- First write the docker file for this
FROM node:20-alpine
LABEL project="learning"
ARG USERNAME=chess
RUN adduser -D -h /apps -s /bin/sh ${USERNAME}
USER ${USERNAME}
WORKDIR /apps
COPY --chown=${USERNAME}:${USERNAME} . /apps/
RUN npm install && npm run build
EXPOSE 4173
CMD ["npm","run","preview","--", "--host", "0.0.0.0"]
- Refer Here for application
- Use multi staged build
- Ensure node js and npm are installed
- execute
npm run build which generates a folder called dist
- Copy this folder into nginx and then the application will work on port 80
- Refer Here for the latest changes in Dockerfile
Docker Security Best Practices
- Run as a non root user
- Prefer using Distroless images
- jdk:
gcr.io/distroless/java17-debian12
- aspdotnetcore:
mcr.microsoft.com/dotnet/aspnet:9.0
- Try rebuilding spc and nop using the above images in final stage.
Like this:
Like Loading...