title: How to set userid in docker-compose container
body: <p>I am starting some docker containers (to run a website) in a docker-compose.yaml file. I want the code for the website to be in a directory on the host, with the files owned by the user who is going to run <code>sudo docker-compose up -d</code> to start the container. This is so the user can easily read or edit them, or add new ones. The website in the docker container will also create some files, and I want them to be owned by the right user too.</p>
  <p>So it would be good if the user <strong>inside</strong> the docker container which is going to run the website scripts had the same UID and GID as the user running docker-compose.</p>
  <p>So far, I have achieved this by working out the UID and GID (using <code>id</code>), and hard coding them into the docker-compose.yaml file.</p>
  <p>However, it would be good if I could move this docker-compose file to other machines, where the UID and GID might not be the same.</p>
  <p>The UID is already available in the environment, and I guess GID could be put there somehow. Is there a way of setting these up and passing them into the docker container so it creates and uses a user with the same UID and GID, so the files have the right ownership and permission?</p>