我正在尝试将文件添加到从官方tomcat映像构建的Docker镜像中.该图像似乎没有root权限,因为如果我运行bash,我以用户tomcat身份登录:
docker run -it tomcat /bin/bash tomcat@06359f7cc4db:/usr/local/tomcat$
如果我指示Dockerfile将文件复制到该容器,则该文件具有权限644,并且所有者为root.据我所知,这似乎是合理的,因为Dockerfile中的所有命令都以root身份运行.但是,如果我尝试将该文件的所有权更改为tomcat:tomcat,则会出现Operation not allowed错误.
为什么我不能更改复制到该图像的文件的权限?
如何复制:
mkdir docker-addfilepermission cd docker-addfilepermission touch test.txt echo 'FROM tomcat COPY test.txt /usr/local/tomcat/webapps/ RUN chown tomcat:tomcat /usr/local/tomcat/webapps/test.txt' > Dockerfile docker build .
docker build的输出.:
Sending build context to Docker daemon 3.072 kB Sending build context to Docker daemon Step 0 : FROM tomcat ---> 44859847ef64 Step 1 : COPY test.txt /usr/local/tomcat/webapps/ ---> Using cache ---> a2ccb92480a4 Step 2 : RUN chown tomcat:tomcat /usr/local/tomcat/webapps/test.txt ---> Running in 208e7ff0ec8f chown: changing ownership of '/usr/local/tomcat/webapps/test.txt': Operation not permitted 2014/11/01 00:30:33 The command [/bin/sh -c chown tomcat:tomcat /usr/local/tomcat/webapps/test.txt] returned a non-zero code: 1