content/guides/angular/develop.md
Complete Containerize Angular application.
In this section, you'll learn how to set up both production and development environments for your containerized Angular application using Docker Compose. This setup allows you to serve a static production build via Nginx and to develop efficiently inside containers using a live-reloading dev server with Compose Watch.
You’ll learn how to:
Use Compose Watch to automatically sync source file changes into your containerized development environment. This provides a seamless, efficient development experience without restarting or rebuilding containers manually.
Create a file named Dockerfile.dev in your project root with the following content:
# =========================================
# Stage 1: Development - Angular Application
# =========================================
# Define the Node.js version to use (Alpine for a small footprint)
ARG NODE_VERSION=24.12.0-alpine
# Set the base image for development
FROM node:${NODE_VERSION} AS dev
# Set environment variable to indicate development mode
ENV NODE_ENV=development
# Set the working directory inside the container
WORKDIR /app
# Copy only the dependency files first to optimize Docker caching
COPY package.json package-lock.json* ./
# Install dependencies using npm with caching to speed up subsequent builds
RUN --mount=type=cache,target=/root/.npm npm install
# Copy all application source files into the container
COPY . .
# Expose the port Angular uses for the dev server (default is 4200)
EXPOSE 4200
# Start the Angular dev server and bind it to all network interfaces
CMD ["npm", "start", "--", "--host=0.0.0.0"]
This file sets up a lightweight development environment for your Angular application using the dev server.
compose.yaml fileOpen your compose.yaml file and define two services: one for production (angular-prod) and one for development (angular-dev).
Here’s an example configuration for an Angular application:
services:
angular-prod:
build:
context: .
dockerfile: Dockerfile
image: docker-angular-sample
ports:
- "8080:8080"
angular-dev:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "4200:4200"
develop:
watch:
- action: sync
path: .
target: /app
angular-prod service builds and serves your static production app using Nginx.angular-dev service runs your Angular development server with live reload and hot module replacement.watch triggers file sync with Compose Watch.[!NOTE] For more details, see the official guide: Use Compose Watch.
After completing the previous steps, your project directory should now contain the following files:
├── docker-angular-sample/
│ ├── Dockerfile
│ ├── Dockerfile.dev
│ ├── .dockerignore
│ ├── compose.yaml
│ ├── nginx.conf
│ └── README.Docker.md
Run the following command from the project root to start the container in watch mode
$ docker compose watch angular-dev
To verify that Compose Watch is working correctly:
Open the src/app/app.component.html file in your text editor.
Locate the following line:
<h1>Docker Angular Sample Application</h1>
Change it to:
<h1>Hello from Docker Compose Watch</h1>
Save the file.
Open your browser at http://localhost:4200.
You should see the updated text appear instantly, without needing to rebuild the container manually. This confirms that file watching and automatic synchronization are working as expected.
In this section, you set up a complete development and production workflow for your Angular application using Docker and Docker Compose.
Here’s what you accomplished:
Dockerfile.dev to streamline local development with hot reloadingangular-dev and angular-prod services in your compose.yaml fileWith this setup, you're now equipped to build, run, and iterate on your Angular app entirely within containers—efficiently and consistently across environments.
Deepen your knowledge and improve your containerized development workflow with these guides:
compose.yaml.In the next section, you'll learn how to run unit tests for your Angular application inside Docker containers. This ensures consistent testing across all environments and removes dependencies on local machine setup.