title: Synchronizing numeric user id's between Dockerfiles and docker-compose.yml?
body: <p>I have a docker-compose newbie question. We have an existing Jenkins build that creates Docker images and pushes them to an in house Artifactory repository. This is driven by using Maven/Docker and two Dockerfiles, one for the app and one for a volume/data container. The Dockerfiles look something like this:</p>
  
  <p>App:</p>
  
  <pre><code>FROM centos
  RUN useradd -u 6666 -ms /bin/bash foouser
  COPY src/main/resources/home/foouser/.bashrc /home/foouser/
  RUN chown -R foouser:foouser /home/foouser
  USER foouser
  COPY src/main/resources/opt/myapp/bin/startup.sh /opt/myapp/bin/
  WORKDIR /home/foouser
  ENTRYPOINT /opt/myapp/bin/startup.sh &amp;&amp; /bin/bash
  </code></pre>
  
  <p>Data container:</p>
  
  <pre><code>FROM centos
  # Environment variable for the path to mount/create. Defaults to /opt/data
  ENV DATA_VOL_PATH="/opt/data"
  
  # Make sure the user id is the same as the container using the volume, otherwise we may run into permission issues on
  # the container mounting the volume.
  RUN useradd -u 6666 -ms /bin/bash foouser &amp;&amp; \
      mkdir -p "$DATA_VOL_PATH" &amp;&amp; \
      chown -R foouser:foouser "$DATA_VOL_PATH"
  VOLUME [ "$DATA_VOL_PATH" ]
  </code></pre>
  
  <p>I omitted stuff like labels, etc for brevity. So the images produced by the build from these Dockerfiles will end up in the local Artifactory repo. We're using Rancher/Cattle to instantiate these images, and I've added the Artifactory repo to Rancher so it can pull from there. The docker-compose.yml file in Rancher looks something like this:</p>
  
  <pre><code># The data/volumes container for the data.
  data:
    image: data-image
  
  # App
  myapp:
    image: app-image
  environment:
    DATA_VOL_PATH:
  volumes_from:
    - data
  </code></pre>
  
  <p>I know that I can pass environment variables from docker-compose (as in the DATA_VOL_PATH above), but I'm confused as to how things work. My understanding is that the commands in the Dockerfile are executed when I run docker build, and after that, the image is immutable. When I instantiate a container based on the image, it creates a new writable UFS layer on top of it if I've understood things correctly. So in the case of the data container, I can't really change the volume once it's created, right? If that assumption is correct, it boils down to 1) how do I best synchronize user ids across two different system (Maven for creating the Docker images, and Rancher for instantiating container clusters), and 2) is it better to drive the creation of the data volume container entirely from docker-compose.yml? How would I then be able to replicate the data container's Dockerfile content in docker-compose.yml?</p>
  
  <p>I assume this is a fairly common scenario, so there must be a few "best practices" solutions out there. Thanks.  </p>