Access named volume from container when not running as root?
Asked Answered
A

1

3

I'm running Celery under Docker Compose. I'd like to make Celery's Flower persistent. So I do:

version: '2'
volumes:
  [...]
  flower_data: {}
[...]
flower:
  image: [base code image]
  ports:
    - "5555:5555"
  volumes:
    - flower_data:/flower
  command:
    celery -A proj flower --port=5555 --persistent=True --db=/flower/flower

However, then I get:

IOError: [Errno 13] Permission denied: 'flower.dat'

I ran the following to elucidate why:

    bash -c "ls -al /flower; whoami; celery -A proj flower --persistent=True --db=/flower/flower"

This made it clear why:

flower_1 | drwxr-xr-x 3 root root 4096 Mar 10 23:05 .
flower_1 | drwxr-xr-x 7 root root 4096 Mar 10 23:05 ..

Namely, the directory is mounted as root, yet in [base code image] I ensure the user running is not root, as per Celery's docks to never run as root:

FROM python:2.7
...
RUN groupadd user && useradd --create-home --home-dir /usrc/src/app -g user user
USER user

What would be the best way for Celery Flower to continue to run not as root, yet be able to use this named volume?

Afroasian answered 10/3, 2016 at 23:32 Comment(0)
A
1

The following works: In the Dockerfile, install sudo and add user to the sudo group, requiring a password:

RUN apt-get update
RUN apt-get -y install sudo
RUN echo "user:SECRET" | chpasswd && adduser user sudo

Then, in the Docker Compose config, the command will be:

bash -c "echo SECRET | sudo -S chown user:user /flower; celery -A proj flower --power=5555 --persistent --db=/flower/flower"

I'm not sure if this is the best way, though, or what the security implications of this are.

Afroasian answered 10/3, 2016 at 23:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.