3 ms·
I have one here: https://github.com/nickjj/docker-flask-example/blob/ca1d48499a4007378bbe363bd5dc117c1a33cc3a/Dockerfile#L47 https://github.com/nickjj/docker-fl
by nickjj 6y ago
I have one here: https://github.com/nickjj/docker-flask-example/blob/ca1d48499a4007378bbe363bd5dc117c1a33cc3a/Dockerfile#L47 https://github.com/nickjj/docker-flask-example/blob/ca1d4849...
The basic idea is you create a user in your Dockerfile, switch to that user with the USER instruction and now future instructions in your Dockerfile will be run as that user.
Also when COPY'ing you'll want to add --chown myuser:myuser too.
The above Dockerfile shows examples of all of that.
I'm not a fan of customizing the UID / GID because then in development with volumes you can get into trouble. Technically you could set UID + GID as build arguments but in practice I never ran into a scenario where this was needed because 99% of the time on a dev box your uid:gid will be 1000:1000 and in production chances are you are in control of provisioning your VPS so your deploy user will be 1000:1000 too. Also you probably won't be using volumes, but if you did they will work out of the box with the above example.