skip to Main Content

I am trying to use docker-compose to create a volume on my MAC, and I ran into a weird behavior that I don’t really understand where docker-compose fails to run because of a volume owning user regardless to the permissions set on the folder.

First, here is my docker file and docker-compose file:

Dockerfile:

FROM debian

RUN groupadd -r test && useradd -r -g test test

VOLUME /var/test
# RUN mkdir -p /var/test && chown -R test:test /var/test
RUN mkdir -p /var/test
COPY test.sh /var/test/test.sh

CMD ["sh", "/var/test/test.sh"]

docker-compose.yml:

version: '3.0'
services:
    test:
      build: .
      volumes:
          - test:/var/test
volumes:
  test:
    driver_opts:
      o: bind
      type: none
      device: "/tmp/vols"

Structure:

|____tmp
| |____Dockerfile
| |____vols
| |____docker-compose.yml

Running docker compose:

➜  /tmp docker-compose up
Creating tmp_test_1 ... error

ERROR: for tmp_test_1  Cannot create container for service test: failed to chmod on /var/lib/docker/volumes/tmp_test/_data: chmod /var/lib/docker/volumes/tmp_test/_data: operation not permitted

ERROR: for test  Cannot create container for service test: failed to chmod on /var/lib/docker/volumes/tmp_test/_data: chmod /var/lib/docker/volumes/tmp_test/_data: operation not permitted
ERROR: Encountered errors while bringing up the project.

Permissions:

drwxrwxrwx   2 root   wheel   64 May  3 12:20 vols

Solutions that worked for me:

  1. Changing the owner of /tmp/vols from root, but I was wondering if there is something better
  2. Creating any file in /tmp/vols seems to solve this, why????

Basically my question is: why does this happen, and how should I fix it?

I can’t find an explanation in the docs for this, and I want to make sure I am not missing anything important.

Thanks!

2

Answers


  1. Chosen as BEST ANSWER

    For now, what we did is just change the file owner to not be root. If anyone will have a better suggestion, I will accept the answer


  2. I had a corrupted _data and _dbs in the folder where docker-compose.yml was located. deleted and recreated the _data and _dbs folders and the system was up and running.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search