DockerContainerUser
- By default docker runs with the user in the container as root 0:0 having full access to stuff in the container, including mounted directories.
Specify specific user
- Why ?
- When using docker to just build local code, mounting it into a nodejs / java / python container, we want the artifacts left in the mounted directory to be owned by the local users
- How ?
- -u ubuntu:ubuntu docker flag to set user.
more generic --user $(id -u ${USER}):$(id -g ${USER})
e.g
docker container run --rm \ -v ${PWD}:/var/www \ -w /var/www \ -u $(id -u ${USER}):$(id -g ${USER}) \ mycontainer/python:7.2 composer
Using user in Dockerfile
- When building docker containers a default user can be set, normally this will be 1000:1000.
- This is normally done to the end of the docker definition to allow root to update packages before switching to user.