Mastering Docker's RUN Instruction: What You Need to Know ??
Pranay Salunkhe
Driving the Future of DevOps ?? | AI-Powered DevOps Engineer ?? | Sharing Insights to Elevate the Tech Community ??
Docker's RUN instruction is more than just a command—it's the backbone of your container builds. If you're not using it to its full potential, you're missing out.
1. Shell Form: The Flexible Friend
This is like typing commands straight into your terminal.
RUN apt-get update && apt-get install -y curl
2. Exec Form: The Secure Alternative
This one ditches the shell and gets right to the point.
RUN ["apt-get", "update"] RUN ["apt-get", "install", "-y", "curl"]
3. Supercharge Your Builds with Mount Options ??
RUN --mount=type=bind,source=/host/path,target=/container/path,readonly
RUN --mount=type=cache,target=/root/.cache/go-build
RUN --mount=type=tmpfs,target=/tmp,tmpfs-size=512m
RUN --mount=type=secret,id=aws,target=/root/.aws/credentials
RUN --mount=type=ssh git clone [email protected]:acewithptanay/repo.git
4. Don’t Overlook These Extras
RUN --network=none dpkg -i /mypackage/mypackage.deb
RUN --security=insecure cat /proc/self/status
?? Ready to take your Docker skills to the next level? Which form or option will you try next?
?? Drop your Docker tips in the comments!
Keep Learning and Keep Sharing!