Docker RUN groupadd && useradd directives have no effect
I have built my base nginx Docker image with a Dockerfile, a snippet of which 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 to the database container and data volume. Later I wanted to add a user to the container so that I can run applications as that user, so I added "RUN groupadd -r luqo33 && useradd -r -g luqo33 luqo33 'to the Dockerfile so that my Dockerfile looks like this:
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 undo the image with docker build -rm .
and then start the whole stack with again docker-compose up
(I have a stack configured in docker-compose.yml).
Unfortunately, although the step RUN groupadd -r luqo33 && useradd -r -g luqo33 luqo33
did not fail, when I entered the shell of a running nginx container, there was no luqo33
user or luqo33
group. Then I ran the same commands ( groupadd -r luqo33 && useradd -r -g luqo33 luqo33
) from the shell and the group and user were added as expected.
Why RUN groupadd -r luqo33 && useradd -r -g luqo33 luqo33
not add user and group to the new container in the Dockerfile on rebuild? I've also tried docker build --no-cache .
with the same effect (or lack thereof). What am I missing here?
source to share
to prevent your build team from using any cached level use the option --no-cache
.
docker build --no-cache .
If you want to do the same with docker-compose:
docker-compose build --no-cache
Also, since you are using docker-compose to start the container, be sure to run it docker-compose rm
, otherwise docker-compose will use the previously generated images.
source to share