How to share a Laravel app codebase in a Docker co

2019-07-24 02:04发布

问题:

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