DEV Community

Cover image for Set up a Dockerfile for your angular application with Nginx
Oumayma JavaScript Developer
Oumayma JavaScript Developer

Posted on

5 1

Set up a Dockerfile for your angular application with Nginx

Running your application in docker container is the first step towards production. We have to make sure that our app can build successfully , independently of our local environment.
Bellow you can find a basic dockerfile for your angular application that uses nginx server to render the html.

FROM node:12-alpine as build

WORKDIR /app

COPY package.json .

RUN yarn install

COPY . .

RUN apk add gettext

RUN yarn build --base-href

FROM nginx:latest

COPY --from=build /app/dist/hr-frontend /usr/share/nginx/html

EXPOSE 80
Enter fullscreen mode Exit fullscreen mode

The above dockerfile will run your application on port 80.
To test it, in the root of your project run:

  1. docker image build --tag <your image name> .
  2. docker run -d -p 8000:80 <your image name> This command will serve your application on port 8000. The port 80 is where your application is running inside the container.
  3. Go to localhost:8000 .

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay