I have a dockerfile that I am using for building docker images for my frontend angular application. Currently it is running as a root user. How do I make it run as non root user from the start itself. I tried using USER app, but it doesn't work
I will paste the dockerfile here
Stage 1: Build Angular
FROM node:24 AS build
WORKDIR /app
COPY package*.json ./
RUN npm install && npm cache clean --force
COPY . .
RUN npm run build:uat
Stage 2: Nginx
FROM nginx:alpine
RUN rm -f /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
Create temporary directories for nginx in writable locations
RUN mkdir -p /tmp/nginx_client_body /tmp/nginx_proxy
/tmp/nginx_fastcgi /tmp/nginx_uwsgi /tmp/nginx_scgi
&& chown -R nginx:nginx /tmp/nginx*
COPY --from=build /app/dist/UI-app/browser /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Below is my nginx.conf file
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /dev/shm/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
Disable access logs completely
access_log off;
client_body_temp_path /tmp/nginx_client_body;
proxy_temp_path /tmp/nginx_proxy;
fastcgi_temp_path /tmp/nginx_fastcgi;
uwsgi_temp_path /tmp/nginx_uwsgi;
scgi_temp_path /tmp/nginx_scgi;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
}
Any help would be appreciated..
Where would I place it in the above docker file
You can specify the container image using "FROM" as follows:
Ok, will try with this. Thank you!