简体   繁体   English

使用docker-compose为主机目录添加权限

[英]Adding permissions to host directory with docker-compose

I'm trying to set up a development environment using docker-compose and my container does not seem to have permissions to the host directory that is mounted to the container, i'm getting this error when running a grunt task that tries to modify folders inside the volume: 我正在尝试使用docker-compose设置开发环境,我的容器似乎没有安装到容器的主机目录的权限,我在运行尝试修改文件夹的grunt任务时遇到此错误在卷内:

app_1                   | Warning: Unable to delete ".tmp" file (EACCES, permission denied '.tmp'). Use --force to continue.

here's my docker file: 这是我的docker文件:

FROM node:0.10

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

RUN apt-get update \
    && apt-get install -y --no-install-recommends ruby-sass \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get clean -y \
    && apt-get autoremove -y

RUN npm install -g grunt-cli bower

RUN groupadd -r node \
&&  useradd -r -m -g node node

RUN chown -R node:node /usr/src/app

USER node

EXPOSE 8080

and my docker-compose file: 和我的docker-compose文件:

app:
  build: .
  dockerfile: Dockerfile.dev
  ports:
   - "9000:9000"
  env_file:
   - ./server/config/env/development.env
  volumes:
   - ./:/usr/src/app:Z
  command: bash -c "npm install && bower install && grunt dev && npm start"

db:
  ports:
   - "27017:27017"
  • I'm running ubuntu 15.10 with docker-compose version 1.5.2, build 7240ff3 我正在使用docker-compose版本1.5.2运行ubuntu 15.10,构建7240ff3
  • Note that I am using the :Z permission 请注意,我使用的是:Z权限

It's just a file permissions thing. 这只是一个文件权限的事情。

The first thing to realise is that the volume you are mounting has different permissions to the folder you create and chown in the Dockerfile. 首先要意识到的是,您安装的卷对您在Dockerfile中创建和填充的文件夹具有不同的权限。 The node user presumably doesn't have permissions to access this folder. 节点用户可能无权访问此文件夹。 You can fix this by running something like: 您可以通过运行以下内容来解决此问题:

$ docker run -u root -v $(pwd):/usr/src/app:Z my_app_image chown -R node:node /usr/src/app

This will change the permissions of the folder on the host. 这将更改主机上文件夹的权限。

Alternatively, if you need to be root to run the npm install && bower install , you could leave the root user as the default user then change to the node user to run the application. 或者,如果您需要root用户来运行npm install && bower install ,您可以将root用户保留为默认用户,然后更改为节点用户以运行该应用程序。 Something like: 就像是:

npm install && bower install && gosu node npm start

Here I've used the gosu tool, which you will need to install in the image. 在这里,我使用了gosu工具,您需要在图像中安装该工具。 It's a little nicer than sudo, as it doesn't start a second process. 它比sudo好一点,因为它没有启动第二个过程。

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

相关问题 如何使用 docker-compose 将 Docker 目录挂载到主机目录中 - How to mount Docker directory into host directory with docker-compose docker 无法使用 docker-compose 将主机目录安装到 docker 容器 - docker unable to mount host directory to docker container with docker-compose 如何使用 docker-compose 将 docker 容器目录映射到主机? - How to map a docker containers directory to the host with docker-compose? 来自主机目录的 Docker 卷与 docker-compose - Docker volume from host directory with docker-compose docker-compose 未在主机目录中安装卷 - docker-compose up not mounting volumes in the host directory 写入主机操作系统的目录 - 通过 docker-compose 文件传递指令 - Writing to the directory of Host OS - Passing the instruction with docker-compose file 如何使用docker-compose挂载主机目录,运行主机时指定“~/path/on/host”,不在docker-compose文件中 - How to mount a host directory with docker-compose, with the "~/path/on/host" to be specified when running the host, not in the docker-compose file docker-compose 未知主机? - docker-compose unknown host? docker-compose/mutagen:更改主机上的文件会更改 docker 容器中该文件的权限 - docker-compose/mutagen: changing a file on the host machine changes the permissions of that file in the docker container docker-compose添加到PATH - docker-compose adding to PATH
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM