cat PrintUserHome.java
public class PrintUserHome {
public static void main(String[] args) {
System.out.println("User home: '" + System.getProperty("user.home") + "'");
}
}
docker run -v `pwd`:/w -w /w --rm -it openjdk:11-slim sh -c 'javac PrintUserHome.java; java PrintUserHome'
User home: '/root'
docker run -v `pwd`:/w -w /w --rm -it --user=$(id -u ${USER}):$(id -g ${USER}) openjdk:11-slim sh -c 'javac PrintUserHome.java; java PrintUserHome'
User home: '?'
See also https://medium.com/redbubble/running-a-docker-container-as-a-non-root-user-7d2e00f8ee15