Skip to main content

Linux File & Folder Permission Fixes (Docker)

What this is

Quick reference for fixing file and folder permission issues when working with Docker containers and mounted volumes.


Why I needed this

Containers often fail to read/write files due to incorrect ownership or permissions on host-mounted volumes.


Key Concepts

Ownership (chown)

  • Controls who owns the file

  • Format:

    user:group
    

Example:

chown stephen:users file.txt

Permissions (chmod)

  • Controls what can be done to the file

  • Format:

    rwx (read, write, execute)
    

Example:

chmod 755 file.txt

When to Use What

Use chown when:

  • Container cannot see or access files

  • Files belong to the wrong user

  • You are using PUID / PGID in Docker

👉 Most common fix for Docker issues


Use chmod when:

  • File exists but cannot be read or written

  • Permissions are too restrictive

👉 Less common than chown for Docker


Common Docker Scenario

Container runs as:

PUID=1000
PGID=1000

Fix ownership:

sudo chown -R 1000:1000 /path/to/folder

Common Permission Fixes

Fix ownership recursively

sudo chown -R 1000:1000 /opt/docker/app

Allow read/write access

sudo chmod -R 755 /opt/docker/app

Allow full access (use carefully)

sudo chmod -R 777 /opt/docker/app

⚠ Only for testing / troubleshooting


How to Check Permissions

View ownership

ls -l

Example output:

drwxr-xr-x 2 1000 1000 folder

Check current user

id

Common Problems / Fixes

Container cannot see files

  • Cause: wrong ownership

  • Fix:

    sudo chown -R <PUID>:<PGID> /path
    

Permission denied error

  • Cause: insufficient permissions

  • Fix:

    sudo chmod -R 755 /path
    

Files created by container not editable

  • Cause: container user mismatch

  • Fix:

    • Match PUID/PGID to your user

    • Or change ownership after creation


NAS mount permission issues

  • Common with NFS/SMB

  • Fix:

    • Ensure correct UID/GID mapping

    • Check mount options


  1. Check ownership:

    ls -l
    
  2. Check container PUID/PGID

  3. Fix ownership:

    sudo chown -R <PUID>:<PGID> /path
    
  4. Only adjust permissions if needed:

    sudo chmod -R 755 /path
    

Quick Reference

Command Purpose
chown Change ownership
chmod Change permissions
ls -l View permissions
id Check user/group

Result

  • Containers can read/write correctly

  • No more “permission denied” errors

  • Consistent file ownership across system


Notes

  • Always prefer chown over chmod for Docker issues

  • Avoid 777 unless troubleshooting

  • Permissions are a common source of Docker problems