Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
WikiName
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Docker file best practices
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== 2. Use Multi-Stage Builds for Smaller Images ==== Multi-stage builds are a game-changer when it comes to reducing the size of your Docker images. With multi-stage builds, you can separate the build environment from the runtime environment. For example, you can compile your application in one stage using all the necessary development dependencies and then copy only the final build artifacts into a minimal runtime image. Hereβs a simple example for a Node.js application: ''<code># Stage 1: Build</code>'' ''<code>FROM node:18-alpine AS build</code>'' ''<code>WORKDIR /app</code>'' ''<code>COPY package*.json ./</code>'' ''<code>RUN npm install</code>'' ''<code>COPY . .</code>'' ''<code>RUN npm run build</code>'' ''<code># Stage 2: Production</code>'' ''<code>FROM nginx:alpine</code>'' ''<code>COPY --from=build /app/build /usr/share/nginx/html</code>''
Summary:
Please note that all contributions to WikiName may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
WikiName:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width