Prepare NGINX config ⚙️
First of all, you will need to setup NGINX config for serving static files from Angular build.
- Create nginx.conf file in the root directory of your project.
touch nginx.conf

2. Write down this code into the file
Thats it! NGINX will serve our static files from Docker container.
Docker 🐳
Docker is one of the important nowadays technologies. It helps us with build, run, and share applications with containers.
- Create Dockerfile
Dockerfile is needed to build docker images which we will use on our virtual machine. Create it in root directory of your project.
touch Dockerfile

Write down this code to file
Deploy 📦
- Build Docker image
Make sure that you are in root directory of your project.
docker build . -t yournickname/yournameofcontainer:latest
docker push yournickname/yournameofcontainer
All the are images is pushed to https://hub.docker.com by default . So, your image will be public and anyone will able to pull it. If you want your images to be private you should create private repository on DockerHub or host your own registry.
2. Pull image from DockerHub
Connect via SSH to your Virtual Machine. And then pull image:
docker pull yournickname/yournameofcontainer:latest
After that you have 2 options: Run container with Docker CLI or with Docker compose:
Docker CLI way:
docker run -p 80:80 -d yournickname/yoyouryournameofcontainer:latest
Note: Flag -p 80:80 means all requests from localhost:80 will redirect to container:80 port. So you can choose the first port, but the second one should be 80 because NGINX container runs on this port by default.
Docker Compose way:
Docker Compose is the tool that helps you to automate common Docker tasks and build microservices. It is much more useful for production than common Docker CLI. First of all, create docker-compose.yml anywhere at your virtual machine.
touch docker-compose.yml
Paste this code to file with Nano, Vim or cat command.
Run this commands:
docker-compose pull angularapp
docker-compose up -d angularapp
Thats all. Now you can go to 80 port of your Virtual Machine and test your app.
Hope this article was useful for you 👨💻
Written by Kletskov Gleb, frontend software engineer in Mail.ru Group.