简体   繁体   English

Docker Volume覆盖文件权限

[英]Docker Volume overwriting file permissions

I have a Dockerfile where I bring in some files and change permissions. 我有一个Dockerfile,其中引入了一些文件并更改了权限。 I also have a docker-compose that creates a volume for nodemon to watch. 我也有一个docker-compose,它为nodemon创建了一个要观看的卷。 I believe that these volumes are overwriting the permissions that I set. 我相信这些卷将覆盖我设置的权限。 When I remove the volumes the app works but I don't get the server restarting. 当我删除卷时,该应用程序可以运行,但无法重启服务器。 When the volumes are there the app crashes due to permissions. 卷存在时,由于权限,应用程序崩溃。 I've tried creating the volume first but perhaps I was doing that wrong. 我尝试过首先创建该卷,但是也许我做错了。

FROM ubuntu:16.04
RUN apt-get update && apt-get install -y --no-install-recommends curl sudo
RUN curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
RUN apt-get install -y nodejs && \
apt-get install --yes build-essential
RUN apt-get install --yes npm

#VOLUME "/usr/local/app"

# Set up C++ dev env
RUN apt-get update && \
   apt-get dist-upgrade -y && \
   apt-get install gcc-multilib g++-multilib cmake wget -y  && \
   apt-get clean autoclean && \
   apt-get autoremove -y
   #wget -O /tmp/conan.deb -L https://github.com/conan-io/conan/releases/download/0.25.1/conan-ubuntu-64_0_25_1.deb && \
   #dpkg -i /tmp/conan.deb

#ADD ./scripts/cmake-build.sh /build.sh
#RUN chmod +x /build.sh
#RUN /build.sh


RUN curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
RUN apt-get install -y nodejs sudo


RUN mkdir -p /usr/local/app
WORKDIR /usr/local/app
COPY package.json /usr/local/app
RUN ["npm", "install"]
RUN npm install --global nodemon
COPY . .


RUN echo "/usr/local/app/dm" > /etc/ld.so.conf.d/mythrift.conf
RUN echo "/usr/lib/x86_64-linux-gnu" >> /etc/ld.so.conf.d/mythrift.conf
RUN echo "/usr/local/lib64" >> /etc/ld.so.conf.d/mythrift.conf
RUN ldconfig

EXPOSE 9090
RUN ["chmod", "+x", "dm/dm3"]
RUN ["chmod", "777", "policy"]
RUN ls -al .
RUN npm -v
RUN node -v

notice at the end where i'm changing permissions. 最后请注意我要更改权限的地方。

version: '3'
services:
  web:
    build: .
    volumes:
      - .:/usr/local/app/
      - /usr/app/node_modules
    command: nodemon
    ports:
      - "3000:3000"

When you mount volumes into a docker container, the files inside are on a lower layer so they are hidden. 当您将卷装载到Docker容器中时,其中的文件位于较低层,因此它们是隐藏的。

In your case, /usr/local/app from the Dockerfile is hidden. 在您的情况下,Dockerfile中的/usr/local/app隐藏。 Its contents are the files from the host machine (the parent directory of docker-compose.yml ). 它的内容是来自主机的文件( docker-compose.yml的父目录)。 You should set the permissions in the host machine. 您应该在主机中设置权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM