---
title: "How to Dockerize a React App: A Step-by-Step Guide for Developers"
description: "A React (Vite + TypeScript) app can be containerized with two Dockerfiles: a development image that runs the Vite dev server with hot reload as the non-root node user, and a multi-stage production image that builds static assets with npm ci and serves them with the lightweight `serve` package."
url: "https://swe.quest/articles/how-to-dockerize-a-react-app-a-step-by-step-guide-for-developers-6c43d07a1a732df2"
canonical: "https://www.docker.com/blog/how-to-dockerize-react-app/"
source: "Docker"
published: "2024-12-10"
difficulty: "medium"
kind: "How-to"
reading_minutes: 14
tags: ["containers","react","frontend","deployment"]
---

# How to Dockerize a React App: A Step-by-Step Guide for Developers

A post on [Docker](https://swe.quest/sources/docker.md), published 2024-12-10, 14 min read, How-to. Original: [https://www.docker.com/blog/how-to-dockerize-react-app/](https://www.docker.com/blog/how-to-dockerize-react-app/)

## Summary

A React (Vite + TypeScript) app can be containerized with two Dockerfiles: a development image that runs the Vite dev server with hot reload as the non-root node user, and a multi-stage production image that builds static assets with npm ci and serves them with the lightweight \`serve\` package. The guide also covers a thorough .dockerignore, build and run commands for both images, and a Compose file whose watch rules sync src changes and rebuild on package.json or vite.config changes. Nginx is noted as the traditional production choice for serving static files. Some leftover legacy snippets for Nginx and CRA appear in the code samples.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Containers](https://swe.quest/tags/containers.md) (Infrastructure)
- [React](https://swe.quest/tags/react.md) (Web & mobile)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)
- [Deployment](https://swe.quest/tags/deployment.md) (Reliability & operations)

## Prerequisites

- React basics ([easy posts on React](https://swe.quest/tags/react.md?difficulty=easy))
- npm
- Docker basics ([easy posts on Containers](https://swe.quest/tags/containers.md?difficulty=easy))

## Keywords

Docker, React, Vite, Docker Compose, Node.js, serve, Nginx

## Related posts

- [Build Apps in Deno with Frameworks such as React, Vue, Express, and more.](https://swe.quest/articles/build-apps-in-deno-with-frameworks-such-as-react-vue-express-and-more-c17610b126d7b402.md): Deno · 2022-11-16 · Medium · 11 min read · JavaScript, Frontend, React, TypeScript
  Deno 1.28's npm support lets you use npm-distributed frameworks like Express, React and Vue directly via \`npm:\` specifiers.
- [Best-in-Class Developer Experience with Vite and Hydrogen](https://swe.quest/articles/best-in-class-developer-experience-with-vite-and-hydrogen-71158a029a23fe79.md): Shopify Engineering · 2022-03-31 · Easy · 8 min read · Build systems, Frontend, React, JavaScript, Developer productivity
  Shopify's Hydrogen storefront framework is built on Vite. Vite serves user code as native ES Modules and pre-bundles and caches only third-party dependencies, which speeds up dev-server startup and hot module replacement compared with bundle-based tools like Webpack.
- [Build and Ship Astro Sites with Deno and Deno Deploy](https://swe.quest/articles/build-and-ship-astro-sites-with-deno-and-deno-deploy-3be8936cebaf2b24.md): Deno · 2023-07-21 · Medium · 12 min read · Frontend, Serverless, Deployment, TypeScript
  Astro sites can be built with the Deno runtime and hosted on Deno Deploy in two modes.
- [What We Learned Migrating From Webpack to Vite](https://swe.quest/articles/what-we-learned-migrating-from-webpack-to-vite-14623bb3ac0e8ed2.md): Neon · 2024-11-20 · Medium · 5 min read · Frontend, Build systems, Developer productivity, JavaScript
  Neon moved its console, a set of SPAs whose HTML is rendered by a Go backend, from webpack to Vite.
- [Moving Railway's Frontend Off Next.js](https://swe.quest/articles/moving-railway-s-frontend-off-next-js-a0f8a20e0dc7a7ef.md): Railway · 2026-04-03 · Medium · 5 min read · Frontend, React, Refactoring & migrations, Build systems, CDN & edge
  Railway migrated its entire production frontend (dashboard, canvas, marketing site, 200+ routes) from the Next.js Pages Router to Vite + TanStack Router/Start in two PRs with zero downtime.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
