在Docker内部创建的文件在主机上受写保护 [英] Files created inside docker are write protected on host

查看:197
本文介绍了在Docker内部创建的文件在主机上受写保护的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用docker容器安装rails和ember。我正在将本地源安装到容器中。我在本地所做的所有更改都反映在容器中。

I am using docker container for rails and ember.I am mounting the source from my local to the container. All the changes I make here on local are reflected in the container.

现在,我想使用 generators 创建文件。文件已创建,但在我的计算机上受到写保护。

Now I want to use generators to create files. The files are created, but they are write protected on my machine.

当我尝试执行 docker-compose运行前端bash ,我在容器内得到了 root @ 061e4159d4ef:/ frontend#超级用户的提示访问权限。在这种模式下,我可以创建文件。这些文件在我的主机中受写保护。

When I try to do docker-compose run frontend bash, I get a root@061e4159d4ef:/frontend# superuser prompt access inside of the container. I can create files when I am in this mode. These files are write protected in my host.

我还尝试过 docker-compose run --user $(id -u):$ (id -g) frontbash ,我得到一个我没有名字!@ 31bea5ae977c:/ frontend $ ,我无法创建任何文件在此模式下。以下是我收到的错误消息。

I have also tried docker-compose run --user "$(id -u):$(id -g)" frontend bash, I get a I have no name!@31bea5ae977c:/frontend$, I am unable to create any file in this mode. Below is the error message that I get.

I have no name!@31bea5ae977c:/frontend$ ember g template about
/frontend/node_modules/ember-cli/node_modules/configstore/node_modules/mkdirp/index.js:90
                    throw err0;
                    ^

Error: EACCES: permission denied, mkdir '/.config'
    at Error (native)
    at Object.fs.mkdirSync (fs.js:916:18)
    at sync (/frontend/node_modules/ember-cli/node_modules/configstore/node_modules/mkdirp/index.js:71:13)
    at Function.sync (/frontend/node_modules/ember-cli/node_modules/configstore/node_modules/mkdirp/index.js:77:24)
    at Object.create.all.get (/frontend/node_modules/ember-cli/node_modules/configstore/index.js:39:13)
    at Object.Configstore (/frontend/node_modules/ember-cli/node_modules/configstore/index.js:28:44)
    at clientId (/frontend/node_modules/ember-cli/lib/cli/index.js:22:21)
    at module.exports (/frontend/node_modules/ember-cli/lib/cli/index.js:65:19)
    at /usr/local/lib/node_modules/ember-cli/bin/ember:26:3
    at /usr/local/lib/node_modules/ember-cli/node_modules/resolve/lib/async.js:44:21

这是我的 Dockerfile

FROM node:6.2

ENV INSTALL_PATH /frontend
RUN mkdir -p $INSTALL_PATH

WORKDIR $INSTALL_PATH

# Copy package.json separately so it's recreated when package.json
# changes.
COPY package.json ./package.json
RUN npm install
COPY . $INSTALL_PATH
RUN npm  install -g phantomjs bower ember-cli ;\
    bower --allow-root install

EXPOSE 4200
EXPOSE 49152

CMD [ "ember", "server" ]

这是我的 docker-compose.yml 文件,请注意它不在当前目录中,而是在父目录中。

Here is my docker-compose.yml file, please note it is not in the current directory, but the parent.

frontend:
   build: "frontend/"
   dockerfile: "Dockerfile"
   environment:
      - EMBER_ENV=development
   ports:
      - "4200:4200"
      - "49152:49152"
   volumes:
      - ./frontend:/frontend

我想知道,如何使用发电机?我是初学者,学习docker。

I want to know, how can I use generateors? I am new to learning docker. Any help is appreciated.

推荐答案

您会得到我没有名字!因此: $(id -u):$(id -g)
您主机中的用户ID和组未链接到

You get the I have no name! because of this: $(id -u):$(id -g) The user id and group in your host are not linked to any user in your container.

解决方案:

执行 chown UID:GID -R / frontend 在容器内 (如果容器已在运行),并且由于某种原因您无法将其停止。否则,您可以只在主机中执行chown命令,然后再次运行容器。 UID和GID 必须属于容器内用户的节点

Execute chown UID:GID -R /frontend inside the container if its already running and you cannot stop it for some reason. Otherwise you could just do the chown command in the host and then run your container again. Node that UID and GID must belong to a user inside the container

示例: chown 101:101 -R /前端与101是www-data的UID:GID。

Example: chown 101:101 -R /frontend with 101 is the UID:GID of www-data.

如果容器中没有其他用户,则您将拥有创建一个新的。为此,您必须创建一个Dockerfile并放置以下内容:

If there are no other user exept root in your container, you will have to create a new one. To do so you must create a Dockerfile and put something like this:

FROM your_image_name
RUN useradd -ms /bin/bash newuser

有关Dockerfile的更多信息,请参见此处,或者只是通过googlin'。

More information about Dockerfiles can be found here or just by googlin' it.

这篇关于在Docker内部创建的文件在主机上受写保护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆