Skip to content

Running motioneye docker as non-root user, can't access /var/run #2540

@towerofpower256

Description

@towerofpower256

If I installed the motioneye docker and ran as root, no issues there.

However I run into an issue when I use the motioneye docker image as another user that is not root (e.g. --user 1003:1003). I started getting errors that are visible in the log saying that motioneye was unable to create the .pid file in the /var/run directory. Motioneye isn't able to start either, and I can't get to the web interface.

The log:

CRITICAL: pid directory "/etc/motioneye/run" does not exist or is not writable
    INFO: hello! this is motionEye server 0.42
CRITICAL: pid directory "/etc/motioneye/run" does not exist or is not writable
    INFO: hello! this is motionEye server 0.42
CRITICAL: pid directory "/etc/motioneye/run" does not exist or is not writable
    INFO: hello! this is motionEye server 0.42

Here's my docker run command, including --user and RUN_UID and RUN_GID arguments:

docker run --name="motioneye" \
    -p 8765:8765 \
    --hostname="motioneye" \
    -v /etc/localtime:/etc/localtime:ro \
    -v /srv/motioneye/etc:/etc/motioneye \
    -v /srv/motioneye/lib:/var/lib/motioneye \
    --restart="always" \
    --detach=true \
    --user 1003:1006 \
    -e "RUN_UID=1003" \
    -e "RUN_GID=1006" \
    ccrisan/motioneye:master-amd64

I was able to get around this by updating motioneye.conf to store the pid file in another directory that motioneye should have access to. This fix appears to be working so far.

# path to the directory where pid files go (must be writable by motionEye)
#run_path /var/run
run_path /etc/motioneye/run # Fix for no access to /var/run within container if non-root

I suspect this is due to the Docker image that the motioneye docker image is utilizing, debian:buster-slim.
https://github.com/debuerreotype/docker-debian-artifacts/blob/337f494fae12a1db13a003cea38e74f43d312ee6/buster/slim/rootfs.tar.xz

Doing some poking around:

  • /run exists, with permissions of 755 (writable by root, read-only to everything else).
  • /var/run exists appears to be a link to /run.

Console output:

I have no name!@motioneye:/run$ ls -l /var/ | grep run
lrwxrwxrwx 1 root root     9 Jul 19  2019 lock -> /run/lock
lrwxrwxrwx 1 root root     4 Jul 19  2019 run -> /run

I have no name!@motioneye:/run$ ls -l / | grep run
drwxr-xr-x   1 root root 4096 Jun 22 10:35 run

I have no name!@motioneye:/run$ ls -l /run        
total 16
drwxrwxrwt 2 root root 4096 Jul 19  2019 lock
drwxr-xr-x 2 root root 4096 Jun 22 10:35 motion
drwxr-xr-x 2 root root 4096 Jul 19  2019 mount
drwxr-xr-x 2 root root 4096 Jul 24  2019 systemd
-rw-rw-r-- 1 root utmp    0 Jul 19  2019 utmp

In the motioneye docker file, I can see that it's trying to own the /var/run folder, but I believe it's only chowning the link to the /run directory, not the /run directory itself, which is causing the issue.

Does that mean the fix is just to update the docker file to include /run in the directories that it's chowning?

chown motion:motion /var/run /var/log /run ....

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions