dockerfile is not creating directory and copying f

2019-07-09 14:48发布

问题:

I have the following in my dockerfile. (There is much more. but I have pasted the relevant part here)

RUN useradd jenkins
USER jenkins

# Maven settings
RUN mkdir ~/.m2
COPY settings.xml ~/.m2/settings.xml

The docker build goes through fine and when I run docker image, I see NO errors.

but I do not see .m2 directory created at /home/jenkins/.m2 in the host filesystem.

I also tried replacing ~ with /home/jenkins and still I do not see .m2 being created.

what am I doing wrong?

Thanks

回答1:

I tried something similar and got

Step 4 : RUN mkdir ~/.m2
 ---> Running in 9216915b2463
mkdir: cannot create directory '/home/jenkins/.m2': No such file or directory

your useradd is not enough to create /home/jenkins

I do for my user gg

RUN useradd -d /home/gg -m -s /bin/bash gg
RUN echo gg:gg | chpasswd
RUN echo 'gg ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/gg
RUN chmod 0440 /etc/sudoers.d/gg
USER gg
ENV HOME /home/gg
WORKDIR /home/gg

This creates the directory of the user gg `