如何在容器内生成与本地用户具有相同权限的文件?

时间:2022-06-08 02:35:13

Whenever I generate a file inside the php container, this file is root, I always need to give chmod -R 777 to be able to edit and this is very annoying, for example, my user is rafaelconceicao and inside the container the permissions are for root and one user that is a sequence of numbers 296823135, whenever I generate a new file, it remains the root permission, making it impossible for me to do the editing. What should I do? (My system is Fedora 27)

每当我在php容器中生成一个文件时,这个文件都是root,我总是需要让chmod -R 777能够编辑,这非常烦人,例如,我的用户是rafaelconceicao,并且容器内部的权限是root和一个用户是一个数字序列296823135,每当我生成一个新文件时,它仍然是root权限,这使我无法进行编辑。我该怎么办? (我的系统是Fedora 27)

My docker files are here: https://github.com/junta1/gfp/tree/develop

我的docker文件在这里:https://github.com/junta1/gfp/tree/develop

I created it from: https://phpdocker.io/generator

我是从https://phpdocker.io/generator创建的

1 个解决方案

#1


0  

The issue discussed in here.

这里讨论的问题。

By default a container starts with user root unless you explicity specify the user. But not that some Docker images expect to be running with root user inside and thus starting them with another user won't work.

默认情况下,容器以root用户启动,除非您明确指定用户。但并不是说一些Docker镜像期望与root用户一起运行,因此用另一个用户启动它们将无法工作。

The problem is that a root user inside the container, will be root outside the container. You might try to start the container with a custom user in the compose file: user: 1000 /path/to/mount.

问题是容器内的root用户将是容器外的root用户。您可以尝试使用compose文件中的自定义用户启动容器:user:1000 / path / to / mount。

That might not work if the Docker image expects a root user. In that case you need to exec into the container using docker exec -it <container-name> bash and run chown -R <your-uid>:<you-uid>

如果Docker镜像需要root用户,那可能不起作用。在这种情况下,您需要使用docker exec -it bash执行容器并运行chown -R :

#1


0  

The issue discussed in here.

这里讨论的问题。

By default a container starts with user root unless you explicity specify the user. But not that some Docker images expect to be running with root user inside and thus starting them with another user won't work.

默认情况下,容器以root用户启动,除非您明确指定用户。但并不是说一些Docker镜像期望与root用户一起运行,因此用另一个用户启动它们将无法工作。

The problem is that a root user inside the container, will be root outside the container. You might try to start the container with a custom user in the compose file: user: 1000 /path/to/mount.

问题是容器内的root用户将是容器外的root用户。您可以尝试使用compose文件中的自定义用户启动容器:user:1000 / path / to / mount。

That might not work if the Docker image expects a root user. In that case you need to exec into the container using docker exec -it <container-name> bash and run chown -R <your-uid>:<you-uid>

如果Docker镜像需要root用户,那可能不起作用。在这种情况下,您需要使用docker exec -it bash执行容器并运行chown -R :