Docker with nginx and Angular – ng build –prod

  angular, docker, nginx

I am using Docker version 19.03.12, build 48a66213fe. I run a nginx server and an Angular application successfully, with the following config below.

Question

How do I build the Angular app with --prod parameters? (I would like to get the performance benefits of a prod build).

I have tried adding the --prod parameter.

#RUN node_modules/.bin/ng build --prod --output-path=/dist

But this results in an error when executing the above command.

docker: Error response from daemon: pull access denied for
ng-nexct-ng-ui-image, repository does not exist or may require ‘docker
login’: denied: requested access to the resource is denied.

Dockerfile

# stage 1
FROM node
WORKDIR /usr/src/app
COPY package.json package.json
#RUN npm install --silent
RUN npm install --legacy-peer-deps
#RUN npm i -D [email protected]
COPY . .
#RUN node_modules/.bin/ng build --prod --output-path=/dist
RUN node_modules/.bin/ng build --output-path=/dist

# stage 2
FROM nginx:alpine
WORKDIR /usr/src/app
RUN rm -rf /usr/share/nginx/html/*
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=0 /dist /usr/share/nginx/html

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

nginx.conf

server {

  listen 80;

  location / {
    root /usr/share/nginx/html;
    index index.html index.htm;
    try_files $uri $uri/ /index.html;
  }

}

deploy.sh

echo "about to build and run nexct-ng-ui ..."
#cd nexct-ng-ui
echo | git branch
echo "git pull ..."
git pull
cd nexct-ng-ui
echo "docker build ..."
docker stop /ng-nexct-ng-ui-container
docker rmi /ng-nexct-ng-ui-image
docker build --pull --rm -f "Dockerfile" -t ng-nexct-ng-ui-image:latest "."
echo "docker run ..."
docker run -t --rm -d  -p 4200:80/tcp --name ng-nexct-ng-ui-container ng-nexct-ng-ui-image:latest

Source: Docker Questions

LEAVE A COMMENT