# Edit the Dockerfile that creates a non-root privilege user and modify the default root user to the newly-created non-root privilege user, as shown here:
##########################################
# Dockerfile to change from root to
# non-root privilege
###########################################
# Base image is CentOS 7
FROM Centos:7
# Add a new user "john" with user id 8877
RUN useradd -u 8877 john
# Change to non-root privilege
USER john
# 2. Proceed to build the Docker image using the “docker build” subcommand, as depicted here:
sudo docker build -t nonrootimage .
# 3. Finally, let’s verify the current user of our container using the id command in a docker run subcommand:
sudo docker run --rm nonrootimage id
# uid=8877(john) gid=8877(john) groups=8877(john)
# Evidently, the container’s user, group, and the groups are now changed to a non-root user.
#Add your user to the docker group
sudo usermod -aG docker [non-root user]