Snessy
Snessy

Reputation: 33

Laravel/Docker - Container unable to save logs into bind mount

I have a docker-compose setup that utilises 1 custom Docker image and 1 MySQL image. The custom Docker image contains Apache/PHP/Composer/Node and uses a bind mount for the whole project directory, which allows developers to use live code reloading.

Due to the way in which bind-mounts work in Docker, I am unable to simply chown/chmod the directory for the default Apache user in my custom Docker image during the build as the bind-mount will simply revert the permissions and ownership back to the host machine setup.

I thought about changing all the permissions/ownership to the default Apache user on the host machine project, so that the Docker image will not be required to change during the build process. However, this does mean that every developer will be required to setup the default Apache user on their machine and add their account to the Apache group (which is not ideal) so that they can make code changes

I'm unsure if I'm misunderstanding how Docker works

Upvotes: 1

Views: 427

Answers (1)

Sven Hakvoort
Sven Hakvoort

Reputation: 3621

If you chown the group with chown -R <current_user>:www-data <project_logs_dir>, it will make the group of apache but let the user stay the owner. If you then set the permissions to 775 both the current user and apache can do what they need to do without having to add the current user to the apache group. This will also make sure apache can only modify the files in the logs dir.

It is true that the developer has to change the permissions himself, but I consider this a good thing since you remain in control and can determine where apache is allowed to write.

I hope this answers your question.

Upvotes: 1

Related Questions