How to share a Laravel app codebase in a Docker container while preserving permissions?

孤者浪人 提交于 2019-12-24 10:59:47

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/40662300/how-to-share-a-laravel-app-codebase-in-a-docker-container-while-preserving-permi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!