[英]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"
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.