title: Permission denied when running `mkdir` inside of a Docker container
body: <p>I am using Docker Compose to run several containers, including one with a Postgres image. I am attempting to add a volume to that container to persist my data across container builds. However, I am receiving an error when it tries to create a directory for this volume within the container.</p>
  
  <p>I run:</p>
  
  <p><code>docker-compose build</code></p>
  
  <p>then</p>
  
  <p><code>docker-compose up</code></p>
  
  <p>And I receive the following error:</p>
  
  <p>ERROR: for cxbenchmark_db_1  Cannot start service db: oci runtime error: container_linux.go:265: starting container process caused "process_linux.go:368: container init caused \"rootfs_linux.go:57: mounting \\"/var/lib/docker/volumes/69845a017b4465e9122852a75ca194db473df95fa218658b8a60fb56eba9be9e/_data\\" to rootfs \\"/var/lib/docker/overlay2/627956d63fb0480448079577a83b0b54f83866fdf31136b7c669541c3f672355/merged\\" at \\"/var/lib/docker/overlay2/627956d63fb0480448079577a83b0b54f83866fdf31136b7c669541c3f672355/merged/var/lib/postgresql/data\\" caused \\"mkdir /var/lib/docker/overlay2/627956d63fb0480448079577a83b0b54f83866fdf31136b7c669541c3f672355/merged/var/lib/postgresql/data: permission denied\\"\""</p>
  
  <p>My full <code>docker-compose.yml</code> looks like this (note the service called <code>db</code> where the volume is defined):</p>
  
  <pre><code>version: '3'  
  
  services:  
    nginx:
      image: nginx:latest
      ports:
        - 80:8000
      volumes:
        - ./src:/src
        - ./config/nginx:/etc/nginx/conf.d
        - ./src/static:/static
      depends_on:
        - web
  
    web:
      build: .
      command: bash -c "python manage.py makemigrations &amp;&amp; python manage.py migrate &amp;&amp; gunicorn cx_benchmark.wsgi -b 0.0.0.0:8000"
      depends_on:
        - db
      volumes:
        - ./src:/src
        - ./src/static:/static
      expose:
        - 8000
  
    db:
      image: postgres:latest
      volumes:
        - /private/var/lib/postgresql:/var/lib/postgresql
      ports:
        - 5432:5432
  </code></pre>
  
  <p>Any ideas for how to solve?</p>