DEV Community

Chandra Shettigar
Chandra Shettigar

Posted on • Originally published at devteds.com on

Building Production-Ready Docker Images With Multi-Stage Builds

In this concise tutorial, discover how to use Docker's Multi-Stage Build process to create production-ready Docker images. Follow our step-by-step guide to writing a multi-stage Dockerfile for a web application and elevate your Docker skills.

If you’re creating a container image (Docker image) for production, image size and security are two essential considerations. Fortunately, Docker’s Multi-Stage builds can help address both concerns.

In the development environment, container images often include development and build tools, as well as dependencies necessary for the development and build process. However, these tools and dependencies can increase the image size and pose a security risk.

By using Docker’s Multi-Stage Build feature, we can separate the development and build stage from the final production stage of creating container images. This way, the image built for production or deployment to any environment, will only contain the necessary components for the app to run in production.

In this short video tutorial, you’ll learn how to write a multi-stage Dockerfile to create both a local development and a production-ready , deployable Docker image.

Here’s a breakdown of the steps you’ll learn in the tutorial:

  1. Containerize an existing web application using Ruby and Ruby on Rails
  2. Start with a simple Dockerfile to build for local development and test running containers locally
  3. Update the Dockerfile to add a multi-stage structure, starting with 2 stages for local development setup
  4. Test running the container locally, built using a multi-stage Dockerfile
  5. Add more stages to package and build a final, production-ready and deployable Docker image
  6. Test running the production-ready image locally using Docker Compose

ACI image

ACI.dev: Best Open-Source Composio Alternative (AI Agent Tooling)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Star our GitHub!

Top comments (0)

Image of Quadratic

Free AI chart generator

Upload data, describe your vision, and get Python-powered, AI-generated charts instantly.

Try Quadratic free

👋 Kindness is contagious

Explore this insightful post in the vibrant DEV Community. Developers from all walks of life are invited to contribute and elevate our shared know-how.

A simple "thank you" could lift spirits—leave your kudos in the comments!

On DEV, passing on wisdom paves our way and unites us. Enjoyed this piece? A brief note of thanks to the writer goes a long way.

Okay