Docker RUN groupadd && useradd directives have no effect

I’ve built my Docker nginx ‘base’ image with a Dockerfile whose fragment is below:

FROM ubuntu:14.04
MAINTAINER Me <me.net>
RUN apt-get update && apt-get install -y supervisor
ADD supervisord.conf /etc/supervisor/conf.d/
RUN apt-get install -y nginx
..

This image was then linked with a database container and data volume. Later, I wanted to add a user to the container so that I could run applications as this user so I added ‘RUN groupadd -r luqo33 && useradd -r -g luqo33 luqo33’ directive to the Dockerfile so that my Dockerfile would look like this:

  • Accessing host's host:port from Docker container in OSX
  • How can I check how many containers are running a certain docker image?
  • How to connect to docker container's link alias from host
  • How to run two python application in docker
  • Python webscraper using selenium works normally but not when headless
  • VM Instances moved - re-connect via docker-machine
  • FROM ubuntu:14.04
    MAINTAINER Me <me.net>
    
    RUN groupadd -r luqo33 && useradd -r -g luqo33 luqo33
    
    RUN apt-get update && apt-get install -y supervisor
    ADD supervisord.conf /etc/supervisor/conf.d/
    RUN apt-get install -y nginx
    ..
    

    Then I rebuit an image with docker build -rm ., and then run the whole stack again with docker-compose up (I have the stack configured in docker-compose.yml).

    Unfortunately, although the RUN groupadd -r luqo33 && useradd -r -g luqo33 luqo33 step did not error out, when I entered the shell of the running nginx container, luqo33 user or luqo33 group were not there. I then executed the same commands (groupadd -r luqo33 && useradd -r -g luqo33 luqo33) from the shell, and the group and user were added as expected.

    Why wouldn’t RUN groupadd -r luqo33 && useradd -r -g luqo33 luqo33 in Dockerfile add the user and the group to the new container upon rebuilding? I also tried docker build --no-cache . with the same effect (or lack of it). What am I missing here?

  • sbt-native-packager for Docker on Mac OS X
  • iptables redirect to different host/tproxy in docker container
  • change ip address for docker
  • Docker build not using cache when running through ansible
  • Docker, varnish, Connection reset by peer
  • Why would `docker stop` kill the docker service?
  • One Solution collect form web for “Docker RUN groupadd && useradd directives have no effect”

    to make sure your build command isn’t making use of any cached layer, use the --no-cache option.

    docker build --no-cache .
    

    If you want the same with docker-compose:

    docker-compose build --no-cache
    

    Also since you are using docker-compose to start the container, make sure to run docker-compose rm or else docker-compose will reuse previously built images.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.