Creating/generating files in a mounted volume on docker container own to regular user and not to root

  docker, permissions, volumes

The Problem: can’t generate/create files on mounted volumes in docker that is not own by root. Throwing permission denied errors when I create and push my user to docker-compose as well.

Scenario:

version: '3.4'
services:
  app:
    image: ubuntu:latest
    command: /home/john/clone_repository_and_generate_reports.sh 
    volumes:
      - "/home/john/:/home/john/"
    environment:
      - NODE_ENV=production
    env_file:
      - ./.config.env
  • My docker-compose.yml file calls to simple bash script that clones a github repository and generate different reports in python, In addition I want this data to be accessible and persistent to user john, unfortunately the the saved files are on root only.

  • If Im adding on Dockerfile additional user RUN addgroup -S developer && adduser -S john -G developer It gets permissions issue accessing to this mounted volume /home/john when running USER=$(id -u):$(id -g) docker-compose up --build --force-recreate -d

Expected behaviour: cloned github repository and generated files owned by john and not by root.

What is the right approach dealing with permission issue on docker?
How can I save these files under john user on this mounted volume?

Source: Docker Questions

LEAVE A COMMENT