How to dockerize an Angular application?
Let's dockerize the "Pokemon" Angular app.

• Full Stack Engineer • Auth0Ambassador • Organizer at AngularHive community • Speaker • Blogger
Search for a command to run...
Let's dockerize the "Pokemon" Angular app.

• Full Stack Engineer • Auth0Ambassador • Organizer at AngularHive community • Speaker • Blogger
No comments yet. Be the first to comment.
Hello awesome people👋, welcome back! In this post, I am going to walk you through how to set up Tailwind CSS in an Angular project. It is going to be the easiest setup you have ever done. Come on in. This post is for projects that are using Angular ...

Hello awesome people👋, welcome back! This is again a super simple post about Angular, but pretty informative and you might have not read about it so far. Let's begin. What is Text Interpolation? Interpolation refers to embedding expressions or just ...

Hello awesome people👋, welcome back. This blog post is going to be a super simple post, and I just wanna share my TailWind CSS learning with you all. What are we going to design? A simple and minimalistic card component with 100% TailWind CSS. Code...

Hello amazing people👋, welcome back! Introduction If you are from a Java background, you must have used/heard about Apache Tomcat server, which is a default server any Java developer works with to deal with Web app development. The landscape has cha...

Project documentation serves as a guide for new developers in a team. Why not create one for an Angular project?

Hello nice people👋, welcome back!
This post is all about dockerizing an Angular application, and I will go through the step-by-step approach from creating a Docker image for an Angular app to Spinning the docker container.
To explore it in your machine, you need Docker installed as a first thing. If you can't install Docker, no worries, jump onto this section.
How to install docker in Windows?
A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.
Source: https://www.docker.com/resources/what-container
A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, and settings.
It's time to get our hands dirty.
#Download Node Alpine image
FROM node:12.16.1-alpine As build
#Setup the working directory
WORKDIR /usr/src/ng-app
#Copy package.json
COPY package.json package-lock.json ./
#Install dependencies
RUN npm install
#Copy other files and folder to working directory
COPY . .
#Build Angular application in PROD mode
RUN npm run build
#Download NGINX Image
FROM nginx:1.15.8-alpine
#Copy built angular app files to NGINX HTML folder
COPY --from=build /usr/src/ng-app/dist/pokemon-app/ /usr/share/nginx/html
Learn more about Dockerfile here .
Execute the below command to build a Docker container image for our Angular application.
docker build -t poke .
Execute the below command to start the docker container to run the application.
docker run -dp 3000:80 poke
Just note that the Docker container will serve the application at port 3000 which in turn is served internally by Nginx at port 80.
Okay, it's time to push the image we created to Docker Hub.
To push an image, we first need to create a repo on Docker Hub.
Go to Docker Hub - https://hub.docker.com/ and login if you need to.
Click the Create Repository button.
For the repo name, use "Poke". Make sure the Visibility is Public.
Click the Create button!
Execute the below commands one by one to push the docker image to Docker Hub.
# Create Image matching your Repo using the TAG command. This creates a tag called "latest".
docker tag poke:latest [DOCKER-ACCOUNT-NAME]/poke:latest
# Push the image to Docker Hub
docker push [DOCKER-ACCOUNT-NAME]/poke:latest
Step 1: Log in to "Play with Docker" - https://labs.play-with-docker.com/ (You need to have a Docker account. Signup!)
Step 2: Click on "Start"
Step 3: Click on "Add new instance" to launch New instance
Step 4: Run the below command in the Web terminal. Replace it with your Docker ID and image name if needed.
docker run -dp 3000:80 askudhay/poke
Step 5: The above command pulls the Pokemon App Docker image and serves it on Port 3000
Step 6: Click on the "3000" link that appears next to the "Open Port" button. You should the app opened in a new tab.

My "Pokemon" Angular app docker image can be found here.
Hope you find this article useful, please feel free to share it with your friends/colleagues.
If you got any questions, feel free to post them in the comments section down below.
Happy learning!
I tweet a lot about Web development, Java, and Productivity Hacks, so feel free to follow me on Twitter at AskUdhay.
Here is one of my recent tweets:
https://www.docker.com/get-started
https://www.docker.com/products/docker-desktop
https://labs.play-with-docker.com/