Skip to content

Instantly share code, notes, and snippets.

@thiagoolsilva
Created December 28, 2021 18:46
Show Gist options
  • Save thiagoolsilva/5ac39108940634d3008951f3635ef322 to your computer and use it in GitHub Desktop.
Save thiagoolsilva/5ac39108940634d3008951f3635ef322 to your computer and use it in GitHub Desktop.
Example of the use of multi stage docker build feature
# Copyright (c) 2021 Thiago Lopes da Silva
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM node:14.17.0-alpine
LABEL stage="builder"
RUN apk update && apk add bash
WORKDIR /app
COPY . /app
RUN addgroup -S container-group && adduser -S container-user -G container-group
RUN chmod a+w .
USER container-user
RUN [ "yarn" ]
RUN [ "yarn", "build" ]
RUN ["rm", "-rf", "node_modules"]
RUN [ "yarn", "--production" ]
CMD [ "node", "dist/src/index.js" ]
@thiagoolsilva
Copy link
Author

For more details about this gist go to the repository https://github.com/thiagoolsilva/multi-stage-build-docker-example

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