I'm starting a new project and want to create a development-specific Docker container that closely resembles my production environment. My aim is to be able to run commands in the container as I would on my local setup, while also having control over the software installed during the build. I'm currently using Debian on WSL2, but other developers might use various Linux distributions like Ubuntu or macOS.
I'm looking for feedback regarding user permissions with my Dockerfile setup, especially concerning creating a non-root user, setting ownership of application files, and ensuring the copied files have the right ownership. I chose UID/GID 1000 for the non-root user to match my host user, but I'd like to know if others might face permission issues with this approach. Here's a snippet of my Dockerfile where I do these setups:
4 Answers
If your production app runs on bare metal, you might not get a perfect 1:1 comparison with your Docker setup. However, controlling your dev environment to match production is a solid idea. Have you considered moving your production environment to Docker? Setting up a private container registry could streamline deployments and help you easily clone your production setup for development.
Have you checked out dev containers? They address many configuration issues and questions about setting up development environments in Docker.
I haven't used them yet, but I'm wary of being locked into VSCode. Also, I'm concerned about the complexity it adds when managing multiple services on a local network.
I appreciate the suggestions for alternative tools, but I'm really just trying to figure out if my method of handling user privileges is effective or if I should tweak it to avoid potential issues. In my previous jobs in Japan, I noticed that using root for commands like `git add .` could lead to ownership issues on files that affected non-root users.
It sounds like you're interested in a remote development environment. Tools like Gitpod might be worth looking into as they simplify things.
You can set environment variables in your Dockerfile and override them at runtime. If you don’t specify them, it’ll use the defaults, so keep that in mind!