Cannot change file owner in docker container #25964
-
Hi, I have a docker-compose that works fine on local and wanted to run it on github actions so I can run my unit tests everytime I push my repo. So basically I have a dockerfile that uses an Alpine image to build php on it. This dockerfile creates the www user, and then uses COPY --chown www:www to copy my project inside the container with the right file ownerships. The thing is, when using actions/checkout on github actions, building the container, and then list the owners of the container files, they all belong to the runner user of the github host. I have tried using RUN chown -R www:www on the dockerfile too, but it didn’t work either. I also tried to run the chown command directly on the github actions file but got a permission denied from the alpine-php container. Do you guys understand what’s going on ? Here’s my Alpine-php dockerfile :
the docker-compose file :
the github actions file :
Actions output : cat /etc/passwd
docker-compose exec -T app ls -la
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Sorry for the delay response. It spent me quite a time to reproduce and troubleshoot this issue.
Finally, I found that In your docker-compose file you added a volume from current working folder (on the hosted runner machine $GITHUB_WORKSPACE ) to /var/www (inside container). |
Beta Was this translation helpful? Give feedback.
-
@yanjingzhu Thank you very much for your reply, you’re absolutely right about the volume being the cause of my issue. Removing the bind solves my issue on Github Actions, which is great, but now, when I’m in the dev environment, my changes on files aren’t taken into account dynamically by the container, which is annoying. What would be the best approach here to you ? |
Beta Was this translation helpful? Give feedback.
-
Is your repo a public one? If possible, please share the repo links here.
fpalamour:
According to your docker-compose file , the plateforme-app container image is |
Beta Was this translation helpful? Give feedback.
-
It’s a private repo and I used to be able to change my local files so it was dynamically changed also inside the container, which is quite convenient when coding. I found a way to deal with that by using the -f option when launching my container so it can take a second config file. In this second file I mount the desired volume so that I can use it only in dev environment. The only issue now is that I’m having issue with permissions as the container user doesn’t have the permission to write on host files (which makes sense security wise), but I’ll figure it out sooner or later and my initial question has already been answered thanks to you. |
Beta Was this translation helpful? Give feedback.
Sorry for the delay response. It spent me quite a time to reproduce and troubleshoot this issue.
I tried in my local machine, using docker-compose also has the same issue. The owner of files are root, not www.
Finally, I found that In your docker-compose file you added a volume from current working folder (on the hosted runner machine $GITHUB_WORKSPACE ) to /var/www (inside container).
This will cover all the existing files under /var/www inside container. And the owner of files on hosted runner is runner.
I would recommend you modi…