5

I can use the current username in a pom.xml-file with ${user.name}, but is there a way to get the uid (userid)?

I use exec-maven-plugin and add arguments to a execution. I've tried different things (${env.UID}, ${user.id}, $UID), but neither work.

I need it to start a process in docker that writes files to a shared directory. If I don't start with the -u-parameter all files will belong to root.
The configuration is like:

<configuration>
  <executable>docker</executable>
  <arguments>
    <argument>run</argument>
    <argument>-u</argument>
    <argument>$UID</argument>
    <argument>...</argument>
  </arguments>
</configuration>
Rainer Jung
  • 636
  • 7
  • 23
  • I checked with http://stackoverflow.com/questions/12317609/maven-overview-for-the-values-of-maven-properties, there seems not to be a value representing the UID. – Rainer Jung Aug 22 '16 at 15:57

2 Answers2

4

I intended to write a maven plugin to provide the property user.id but then I did not find a way to get the userid with standard java methods.
There are two projects (Java Native Access, Java Native Interface) to have direct access to native informations, but so far I haven't found a way to get the UID.

I fixed my problem by adding a umask-call in my Dockerfile. I strongly recomend to use a solution that does not requires the user-id within maven.

But working on the issue I created a solution for others that really need this. It takes the user.name-property from the system-properties and then opens the passwd-file to search for the uid. Of course this will only work for unix-like systems and it couples the build directly with your environment, so use this solution wisely (idealy not at all).
To use my solution, add this to your pom.xml:

<plugin>
  <!-- Plugin only works with unix-like environments, please use it wisely! -->
  <groupId>org.rjung.util</groupId>
  <artifactId>user-id-maven-plugin</artifactId>
  <version>1.0</version>
  <executions>
    <execution>
      <goals>
        <goal>user-id</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Rainer Jung
  • 636
  • 7
  • 23
3

Assuming I understand you correctly, does this not work?

${user.name}

Possible duplicate of this.

Community
  • 1
  • 1
Thomas Kåsene
  • 5,301
  • 3
  • 18
  • 30
  • Agreed. Quoted from ``Docker run --help`` : `-u, --user Username or UID (format: [:])` – Aaron Aug 22 '16 at 16:17
  • 4
    I only can use the username if the user is created in the image. I also cannot map the internal UID to the external UID through the shared filesystem. The main goal is to have the files created in docker to belong to the user outside of docker. It says in the documentation: The image developer can create additional users. Those users are accessible by name. When passing a numeric ID, the user does not have to exist in the container. – Rainer Jung Aug 22 '16 at 17:48