5

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.

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

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.

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

Here is my 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" ]

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

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

Fares
  • 531
  • 4
  • 9
aks
  • 8,796
  • 11
  • 50
  • 78

1 Answers1

5

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.

Solution:

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

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

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

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

Fares
  • 531
  • 4
  • 9
  • What do you mean by cannot stop out for some reason? – aks Jul 06 '16 at 14:57
  • 1
    I don't know, if you're in production or something. – Fares Jul 06 '16 at 15:00
  • No it is on development. For this it seems that I'll have to create a user inside the container corresponding to my local user. – aks Jul 06 '16 at 15:02
  • @AnkitSinghaniya Yes, you should. You don't have any other options. You'll have to create a Dockerfile in which you create that user. I'm updating my answer if you don't know how to do this. – Fares Jul 06 '16 at 18:24
  • 1
    @Fares this workflow doesn't seem natural to me. Docker meant to be portable and used any where. This doesn't allow my other developers to integrate easily. There is another way I am trying that out too. If that doesn't work, I'll mark this as correct. – aks Jul 07 '16 at 04:27
  • @AnkitSinghaniya Creating a new user still makes things portable and easy to integrate. It takes about one minute to do this... – Fares Jul 07 '16 at 07:14
  • Yes, It seems I was thinking about terminal session execution. [this link](http://stackoverflow.com/questions/27701930/add-user-to-docker-container) completes it. – aks Jul 07 '16 at 07:40