1

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!

Community
  • 1
  • 1
alariva
  • 2,051
  • 1
  • 22
  • 37

1 Answers1

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

Carlos Rafael Ramirez
  • 5,984
  • 1
  • 29
  • 36
  • Thanks for the answer, its clarifying. Ill try some changes and post back. Yes, I meant the changes under `docker exec`, and yes I want the dockerfile to be portable for other users, thats why I prefer relying on hardcoded UIDs or such parameters as little as possible. Ill post back! – alariva Nov 17 '16 at 19:04
  • I get the point, however, I'm not able to make it work. Running the container as another user makes mysqld to fail. And using exec as another user makes me unable to alter the files created as root. Is there any way to switch the UID (getting this value through external params) on build time? – alariva Nov 17 '16 at 23:22
  • Yes using the USER directive and AUX in the Dockerfile. You can for example leave the docker run as is but altering the users in docker exec – Carlos Rafael Ramirez Nov 18 '16 at 00:19
  • Carlos, here the [changes](https://github.com/timegridio/dockerfiles/commit/c63344f831315cbf7058c37790dd0630bc1ff4e5) I made to my *Dockerfile* from what I understood of your answer. It actually seems to work nice for what I was seeking. I still feel that something else may pop-up, but for now, seems good. I'd appreciate very much your review on the changes, suggestions are welcome. Thanks again for hints! – alariva Nov 18 '16 at 02:04