Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't access own directory in docker created by ADD/chown/chmod in Dockerfile

Tags:

docker

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

like image 634
Larry Cai Avatar asked Feb 12 '23 16:02

Larry Cai


1 Answers

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
like image 117
Thomasleveil Avatar answered May 19 '23 03:05

Thomasleveil