Last active
June 14, 2021 01:30
-
-
Save cgcardona/860e41c05c6ca2ffb8af47562320bf1d to your computer and use it in GitHub Desktop.
Example showing how to get a NodeJS app into a Docker container w/ cached layers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set the baseImage. | |
# The ECR node:14 image is noticeably faster than dockerhub. | |
FROM public.ecr.aws/bitnami/node:14 | |
# Set the working dir to /example-directory. | |
WORKDIR /example-directory | |
# Rather than copying the entire working directory only copy the package.json file. | |
# This takes advantage of cached Docker layers and doesn't rebuild the modules each time the container is rebuilt. | |
# If the package.json file changes then the modules will be rebuilt. | |
COPY package.json yarn.lock ./ | |
# Install dependencies | |
RUN yarn install | |
# Bundle app source | |
COPY . . | |
# Create example user. | |
# --system Create a system account | |
# --group Create a system group | |
RUN adduser --system --group example | |
# Change owner from root -> example. | |
RUN chown -R example /example-directory | |
# Set the username. | |
USER example | |
# Define the network port that this container will listen on at runtime. | |
EXPOSE 507 | |
# Start the app. | |
CMD [ "yarn", "build" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment