← Back to Devops Blogs

Dockerizing an Angular App

2025-07-19📖 3 min read

Share:

🐳 Blog 2: Dockerizing an Angular App with NGINX for Production (Minikube Ready)

Welcome to Part 2 of our DevOps with Angular & Minikube series!

In this blog, you’ll Dockerize your Angular application using NGINX and prepare the container image to run inside Minikube — entirely on your Windows machine, without Docker Desktop.


🤔 What Does It Mean to "Dockerize" and Why Do We Do It?

"Dockerize" means packaging an application and its dependencies into a Docker image. When run, this image becomes a Docker container. It ensures consistency across environments ("works everywhere!") and provides isolation for your app.


🎯 What You'll Learn

  • Create a Dockerfile for Angular
  • Use NGINX to serve Angular static files
  • Build the image inside Minikube’s Docker engine
  • (Optionally) test the image locally using Docker

🧱 Step 1: Build Your Angular App

Before you containerize anything, make sure your app compiles correctly:

npm install
npm run build --configuration=production

This will generate your production files in:

dist/<your-app-name>/

🐳 Step 2: Create the Dockerfile

In your Angular project root, create a file named Dockerfile:

# Stage 1: Build Angular App
FROM node:18-alpine as build

WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build --configuration=production

# Stage 2: Serve with NGINX
FROM nginx:stable-alpine

# Clean default NGINX web dir
RUN rm -rf /usr/share/nginx/html/*

# Copy Angular dist output
COPY --from=build /app/dist/* /usr/share/nginx/html/

# Optional custom config:
# COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]

🧠 This is a multi-stage Dockerfile: one stage builds Angular, the second serves it with NGINX.


⚙️ Step 3: Build Docker Image Inside Minikube

If you use docker build normally, the image is created on your host — and Minikube can't access it.

Instead, build it inside Minikube's Docker engine:

🔁 Configure Docker to use Minikube’s internal engine: Use Git Bash or PowerShell (Run as Administrator):

For Git Bash:

eval $(minikube docker-env)

For PowerShell:

& minikube -p minikube docker-env --shell powershell | Invoke-Expression

✅ Now, build the image:

docker build -t angular-app:latest .

This image is now stored inside Minikube’s Docker environment — no external registry needed.


🔬 Step 4: (Optional) Test Locally with Docker

You can quickly test the container before deploying it:

docker run -d -p 8080:80 angular-app:latest

Visit http://localhost:8080 in your browser.

Stop the container once verified:

docker ps
docker stop <container_id>

✅ Recap

You’ve now:

  • Compiled your Angular app for production
  • Dockerized it with NGINX
  • Built the image inside Minikube (no Docker Desktop required)
  • (Optional) verified it with docker run