Editing
Docker
(section)
Jump to navigation
Jump to search
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!
== <span style="color: #FFFFFF;">Analyzing</span> == '''Image size matters.''' Large images take longer to push, pull, and start. Common sources of bloat: * Using a full OS base image (ubuntu:latest ~80MB) instead of a slim or Alpine variant (~5MB) * Build tools (compilers, dev dependencies) left in the final image * File copies that include unnecessary files (.git, node_modules on Node, __pycache__ on Python) '''Multi-stage builds''' solve the build-tools problem: use one stage with a full build environment, then copy only the compiled artifact into a minimal final stage. :<code>FROM golang:1.22 AS builder WORKDIR /app COPY . . RUN go build -o server . FROM alpine:3.19 COPY --from=builder /app/server /server CMD ["/server"]</code> The final image contains only Alpine and the compiled binary οΏ½ no Go toolchain. '''Layer cache invalidation''' is a common performance trap. Copying the full source before installing dependencies means any code change invalidates the dependency install layer. Always copy dependency manifests first, install, then copy source code. '''Container statefulness''': containers are designed to be ephemeral. Any data written inside a container's writable layer is lost when the container is removed. Databases, uploaded files, and anything that must persist must use volumes or external storage. '''Networking modes''': containers on the same Docker network can reach each other by service name. Containers on different networks cannot see each other by default. The default bridge network does not provide DNS resolution between containers οΏ½ use a named network with Compose or explicit network creation. </div> <div style="background-color: #483D8B; color: #FFFFFF; padding: 20px; border-radius: 8px; margin-bottom: 15px;">
Summary:
Please note that all contributions to BloomWiki 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
BloomWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information