如何在Docker容器中共享Laravel应用程序代码库,同时保留权限? [英] How to share a Laravel app codebase in a Docker container while preserving permissions?
问题描述
到目前为止,我已经实现了大部分我需要的功能,但是每个命令遇到容器(如 composer install
等等)将使用容器化的根
的UID更改我的代码库文件,在我的主机中生成权限冲突。
到目前为止,这是我的Dockerfile
https://github.com/timegridio/dockerfiles 和我的项目代码库(在需要的情况下)。
在我的研究中,已经尝试了这个问题和这篇文章的建议,我认为似乎与我所需要的非常接近。然而,我没有成功与这些aproaches并且有错误(参见问题评论我粘贴输出,但我不想混合这个方法对这个问题。)。
谢谢为您的时间!
在构建过程中(在Dockerfile中)所做的一切都不会改变您在主机。只有在您在 docker exec
中执行的操作或应用程序本身将更改文件时会发生什么。所以当你执行你的容器指定你的主机UID和GID:
docker run -p 8000:8000 -v〜/ timegrid / :/ var / www / timegrid -u =< UID> -g = LT; GID> timegrid:最新
所有这些都将用于这些ids。如果您的应用程序运行不好,可能需要在目录创建之前在Docker文件中指定 USER
指令。
主机挂载的卷总是复杂的,许可的事情让我们总是头疼。您可以使用与主机用户相同的ids来定义用户,但是您的Dockerfile仅适用于您。如果您这样做,您可以使用 AUX
指令来指定ids。
关心
I've created a dockerfile to containerize my Laravel app for local development environment.
So far I've achieved most of what I need, however, every command ran into the container (like composer install
and such) will alter my codebase files with the containerized root
's UID and generate permissions conflicts in my host machine.
So far, this is my dockerfile
https://github.com/timegridio/dockerfiles and my project codebase (in case needed).
On my research, I've tried some hints given on this question and the recommendations of this article, which I believe seem to be pretty close of what I need. However I had no success with those aproaches and got errors (See the question comments where I pasted outputs, but I did not want to mix that approach on this question just yet.).
Thanks for your time!
Everything you make in the build process (in the Dockerfile) won't alter what you have in your host machine. Only what happens after what you do in docker exec
or what the application itself to will alter your files. So when you execute your container specify your host UID and GID:
docker run -p 8000:8000 -v ~/timegrid/:/var/www/timegrid -u=<UID> -g=<GID> timegrid:latest
Everything will be made for these ids. If your application behaves badly, probably you need to specify the USER
directive in the Dockerfile before the directory creation.
Host mounted volumes are always complicated in some way and permission things give us always headaches. You can define a user with the same ids as your host user, but your Dockerfile will work only for you. If you decide this way you can use AUX
directive to specify the ids.
Regards
这篇关于如何在Docker容器中共享Laravel应用程序代码库,同时保留权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!