Is it redundant in a Dockfile to run USER root since you're already root?
docker, dockerfile
Solution
Yes, it's redundant, but there's almost no downside to leaving this redundancy in. This may have been done to develop against other images, or to support uses that may swap out the base image. It could be done to prevent future issues if the upstream image changes it's behavior. Or they may just want to be explicit so it's clear this container needs to run commands as root.
This assumes that you have verified that the base image is running as root (as the OP has done). For others with this question, if you run:
docker image inspect --format '{{.Config.User}}' $base_image_name
and see anything other than an empty string or `root`, then you need `USER root` to change the user for tasks that require that access (e.g. installing packages, changing filesystem permissions, and writing files in folders not owned by your user). After performing those steps (in separate `RUN` lines) be sure to change back to the non-privileged user in your released image with another `USER youruser` line.
Problem
Looking at this Dockerfile it starts with: ``` FROM sequenceiq/pam:centos-6.5 MAINTAINER SequenceIQ USER root ``` Now that seems redundant, since by default you'd already be `root`. But for argument's sake - let's look at the parent Dockerfile....that doesn't change the user. Now let's look at the grandparent Dockerfile. (It doesn't seem to be available). My question is: Is it redundant in a Dockfile to run USER root since you're already root?