The short, sharp, and shiny of it all is docker containers usually run as root, so when you mount your local file system to it, it writes files as roo

Taylor - Getting Docker to not suck for Development

submited by
Style Pass
2024-11-16 14:30:15

The short, sharp, and shiny of it all is docker containers usually run as root, so when you mount your local file system to it, it writes files as root to your machine. This bugs me and causes issues. The fix is to build your docker image with a non-root user that has your UID and GID. You can see my example in this zip file.

No, not him. I’ve just finished reading and working through Sustainable Dev Environments with Docker and Bash by Dave Copeland. It was a great read and has helped me reach a place where I’m now happy with docker as a development environment (so far, it’s only been a couple days). This is actually something I’ve tried to do a few times in the past, but have never found anything that worked sensibly or didn’t add a lot of friction to my development experience. Dave’s approach of using a running container that does nothing and you launch your commands via a helpful dx/exec has proven to remove nearly all of that friction.

Now, you’ll notice I said nearly. That’s because it didn’t cross one of my biggest complaints about using docker as a development environment off my list. And that complaint relates to file ownership.

Leave a Comment