受欢迎的博客标签

Docker File Permissions Between Host and Container

Published

Linux doesn’t care about usernames. It cares about User IDs (UIDs) and Group IDs (GIDs).

Host User: When you work on your computer, you are logged in as a user. 

The Container User: A Docker container runs its own isolated Linux operating system. This system has its own set of users. Docker containers share the host's kernel but not its user namespace.

 

Table of Contents

The official php (Apache) image runs as the www-data user, which has a UID of 33.
The official nginx image runs as the nginx user, which has a UID of 82.
The official .net images run as a user named app, which has a UID of 1654.
The official PostgreSQL images run as a user named postgres,which has a UID of 999.

 

 Root Cause

Here’s the conflict:

The Problem: The user inside the container (e.g., www-data, UID 33) doesn’t have permission to write to the folder on your host machine (owned by your-user, UID 1000).

You create ./my-app-code on your host. Its owner is uid=1000.
You start a container  that runs its process as www-data (uid=33).
Docker maps ./my-app-code to /var/www/html inside the container.
Your application (running as uid=33) tries to create a file (like a cache file or a CSS file generated by Elementor) inside /var/www/html.
The Linux kernel on your host checks the permissions. It sees that a user with uid=33 is trying to write to a directory owned by uid=1000.
The kernel correctly says: “Permission denied.”

 

Solution

 

 

 

 

https://elementor.com/blog/permission-denied-error-in-docker/

 

https://www.mironsoft.de/en/blog/docker-file-permissions-between-host-and-container