Blog Home
Updated: 2023 Oct 09

Example Dockerfile for non-root application

The following example is a Dockerfile that runs an application as a non-root user with non-group membership.

Dockerfile

FROM ubuntu:latest
 
#Update and install the make utility
RUN apt update && apt install -y make
 
#Copy the source from a folder called “code” and build the application with the make utility
COPY . /code
RUN make /code
 
#Create a new user (user1) and new group (group1); then switch into that user’s context
RUN useradd user1 && groupadd group1
USER user1:group1
 
#Set the default entrypoint for the container
CMD /code/app

Reference:

Comments:

Email questions, comments, and corrections to hi@smartisan.dev.

Submissions may appear publicly on this website, unless requested otherwise in your email.