Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

281
Views
Docker permissions host user volume in the container

I'm looking for a "clean" solution to share a volume and share the permissions. I mean, if it's possible, I would like to have the same user in my container than the local user who has started it.

Currently, I'm using:

docker run --rm -v ~/Projects/:/projects/ mycontainer

It works but the problem is, when my container writes some content in this volume, it's root who is the proprietary and not my local user.

What is the best way to handle this issue? If it's possible, I don't want to create user information in the Dockerfile, because I want to share this container with colleagues and I want to avoid any permissions issue between the local user and the container user.

Thanks

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can specify the user on the docker run command:

--user, -u      Username or UID (format: <name|uid>[:<group|gid>])

If you use the numeric UID and GID of the host user, the created files will belong to it.

about 4 years ago · Santiago Trujillo Report

0

Thank for your help Henry.

My complete solution was:

docker run --rm -e USER_ID=$(echo "$UID") -v ~/Projects/:/projects/ mycontainer

And I've this script as entrypoint value:

#!/bin/bash
adduser -D -u $USER_ID alpine &>/dev/null
cd /projects/
su alpine -c 'mycommand ...."

With this my container can access and add/modify content in the Projects folder with the same permissions as my local user.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!