DEV Community

Cover image for Use a non root user in your Docker
Antoine
Antoine

Posted on

Use a non root user in your Docker

Photo by Robert Katzki on Unsplash

Due to an Angular migration, the following command requires to run on a non root user due to post-install custom script in our project:

RUN npm install
Enter fullscreen mode Exit fullscreen mode

In order to do this we had to:

  • create a user
RUN useradd -ms /bin/bash user
Enter fullscreen mode Exit fullscreen mode
  • change ownership of workdir
RUN chown user ../app
Enter fullscreen mode Exit fullscreen mode
  • copy files using the new user
COPY --chown=user src/myapp/myapp.csproj src/myapp/
Enter fullscreen mode Exit fullscreen mode
  • change user
USER user
Enter fullscreen mode Exit fullscreen mode

Hope this helps !

Top comments (0)