Different file owner inside Docker container and in host machine

I am facing a issue related to Docker users.
I run my container as gitlab-runner using the following command:

docker run --name testes_cashlink --hostname testes_cashlink --user gitlab-runner --privileged -t -v $DIR_TESTES:/cashlink_host -v $DIR_BATS:/bats -v $DIR_PROJETO:/cashlink_war docker-cashlink-ci /bats/run.sh

The files created inside the docker container show owner gitlab-runner, however, the same files show in my host machine as owner roggerfernandes. gitlab-runner must be the owner of files created inside Docker container as well as host machine.

  • Install nodejs using docker
  • How would you use Hashicorp's Nomad 'template stanza' to generate an nginx config file through the Nomad job file?
  • Need to install Perl AND Linux
  • How to commit changed data in a mysql container to a new image
  • docker : where to find the docker-compose.yml and the physical image of the machine
  • AWS opsworks docker service discovery
  • docker hornetQ standalone … jnp issue
  • Access docker-machine VM ports without port forwarding
  • Liberty Docker Image is not running
  • Docker volume does not persist data
  • Wordpress & Nginx with Docker: Static files not loaded
  • Opening Port in Docker Container
  • One Solution collect form web for “Different file owner inside Docker container and in host machine”

    Filesystems, at least in Unix- and Linux-like systems (including macOS), file owners are a number, not a name. Various tools such as ls will translate the number into a name for convenience, but it is still just a number. Your user gitlab-runner in the container, and the user roggerfernandes on the host system, have the same UID. You can find the numeric ID by running the id command.

    Here it is on my laptop (reformatted a bit for readability):

    $ id
    uid=501(dan) gid=20(staff) groups=20(staff),12(everyone),61(localaccounts),

    Here you see at the beginning my UID is 501.

    You can also run this command with a username, e.g. id gitlab-runner inside the container.

    docker exec testes_cashlink id gitlab-runner

    So when the user in the container owns a file, it is stored as a numeric ID (quite likely 1000, a common default). When you look on your host system, the mechanism that translates the number into a username just has a different username in its result than you would see inside the container.

    If you need a specific user ID inside the container, you need to modify your Dockerfile so that when creating the user, you specify its uid. For example:

    RUN useradd -u 1005 <other options> gitlab-runner
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.