问题描述
我尝试将ssh私钥从Dockerfile添加到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
这是 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
构建图像并运行到容器中并向用户 larry
su后,我得到了
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
也许我错过了Docker中的一些基本概念?只是从普通的unix用户角度进行接线.
Maybe I missed some basic concept in docker ? Just wired from normal unix user point of view.
我也将其放在github中 https://github.com/dotcloud/docker/issues/1295#issuecomment-46700769
I put this in github as well https://github.com/dotcloud/docker/issues/1295#issuecomment-46700769
推荐答案
您刚刚遇到了错误#6047 基本上说,在 chmod
之后运行时,它们是 chown
的问题.
You just met bug #6047 which basically says they are issues with chown
when run after chmod
.
以下Dockerfile将起作用:
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
这篇关于在Dockerfile中由ADD/chown/chmod创建的docker中无法访问自己的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!