I try to add ssh private key into docker building from Dockerfile, it looks wired that I can't access it even it looks like I have full permission
Docker Version: 1.0.0
Docker host: ubuntu 14.04
Here is the Dockerfile
FROM ubuntu:latest
ENV HOME /home/larry
RUN useradd larry && echo 'larry:docker' | chpasswd
RUN echo "larry ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
# arrange ssh key
ADD larry.id_rsa $HOME/.ssh/id_rsa
RUN \
chmod 700 $HOME/.ssh &&\
chmod 600 $HOME/.ssh/id_rsa
RUN chown -R larry:larry $HOME
After I build the image and run into container and su to user larry
, I got
$ id
uid=1000(larry) gid=1000(larry) groups=1000(larry)
$ ls -al
total 12
drwxr-xr-x 5 larry larry 4096 Jun 21 01:29 .
drwxr-xr-x 5 root root 4096 Jun 21 01:29 ..
drwx------ 2 larry larry 4096 Jun 21 01:29 .ssh
$ cd .ssh
-su: cd: .ssh: Permission denied
Maybe I missed some basic concept in docker ? Just wired from normal unix user point of view.
I put this in github as well https://github.com/dotcloud/docker/issues/1295#issuecomment-46700769
You just met bug #6047 which basically says they are issues with chown
when run after chmod
.
The following Dockerfile will work:
FROM ubuntu:latest
ENV HOME /home/larry
RUN useradd larry && echo 'larry:docker' | chpasswd
RUN echo "larry ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
# arrange ssh key
ADD larry.id_rsa $HOME/.ssh/id_rsa
RUN chown -R larry:larry $HOME
RUN \
chmod 700 $HOME/.ssh &&\
chmod 600 $HOME/.ssh/id_rsa
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With