WebThingsIO / gateway-docker

Legacy docker image for WebThings Gateway - now moved to main gateway repo at https://github.com/WebThingsIO/gateway
Mozilla Public License 2.0
72 stars 25 forks source link

Container unable to create node directory #11

Closed NuroDev closed 6 years ago

NuroDev commented 6 years ago

Ran the provided script for ARM devices (Running on a Raspberry Pi Model 3 B) and container starts successfully with no errors on launch. However when checking the logs, the logs are spammed with the error below:

+ MOZIOT_HOME=/home/node/.mozilla-iot
+ args=
+ is_docker_container
+ '[' -f /.dockerenv ']'
+ return 0
+ mkdir -p /home/node/.mozilla-iot/log
mkdir: cannot create directory '/home/node/.mozilla-iot/log': Permission denied

Is there something I am doing wrong or an issue with the image?

mrstegeman commented 6 years ago

Seems like a permissions issue with the volume you mapped into the container. I believe the node user in the container has uid/gid of 1000/1000, so the owner of your mapped directory needs to match.

NuroDev commented 6 years ago

That is odd as I am creating the container under the pi user which has an id of 1000 for both uid and gid. I connected to the container and tried to manually create the directory, but to create it required sudo perms. Is there a different perm I may be missing to allow it create the directory?

dhylands commented 6 years ago

I noticed that the directory you're trying to create is in /home/node and not /home/pi. I suspect that the permissions on /home/node (and subdirectories) may not be correct. Having said that, I've not really used docker on the Pi, so ignore me if this is just noise.

dhylands commented 6 years ago

You definitely will need sudo permissions to create the /home/node directory, but that directory should be owned by a user and you shouldn't need sudo permissions to create sub directories under /home/node if you're running as the owner.

mrstegeman commented 6 years ago

@dhylands In the docker container, node is the primary user, so that directory already exists.

mrstegeman commented 6 years ago

@NuroDev What command are you using to start the container? I have a Raspberry Pi to test with again, so I'd like to try to reproduce.

NuroDev commented 6 years ago

Using docker-compose, but same issue when running default provided command in README.md.

docker-compose.yml

version: "2"

services:
  gateway:
    image:  mozillaiot/gateway:arm
    container_name: gateway
    restart: always
    network_mode: host
    cap_add:
      - NET_ADMIN
    volumes:
      - /home/nuro/gateway/:/home/node/.mozilla-iot
mrstegeman commented 6 years ago

@NuroDev Why are you using /home/nuro/gateway? I thought you were running as the pi user? In that case, it should be /home/pi/gateway.

NuroDev commented 6 years ago

My mistake, I mean't to say /home/pi/gateway. I usually use a .env file to store volume paths but for the sake commenting just manually input it 😅

mrstegeman commented 6 years ago

Haha, ok. So with /home/pi/gateway, it's still broken? Can you paste the output of stat /home/pi/gateway?

NuroDev commented 6 years ago
  File: /home/pi/gateway/
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 802h/2050d      Inode: 255185      Links: 4
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2018-10-06 22:48:36.349122726 +0000
Modify: 2018-10-07 00:00:05.970806589 +0000
Change: 2018-10-07 00:00:05.970806589 +0000
 Birth: -
mrstegeman commented 6 years ago

The directory is owned by root. This should fix your issue:

chown -R 1000:1000 /home/pi/gateway
NuroDev commented 6 years ago

That seemed to fix perfectly! Thank you ❤️ 😄