Skip to content

Instantly share code, notes, and snippets.

@gesellix
Created January 29, 2019 20:58
Show Gist options
  • Save gesellix/e20551f1400a37d14f29d8ebc8e9fa98 to your computer and use it in GitHub Desktop.
Save gesellix/e20551f1400a37d14f29d8ebc8e9fa98 to your computer and use it in GitHub Desktop.
Java and custom UID mapping in (Docker) containers
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: '?'
public class PrintUserHome {
public static void main(String[] args) {
System.out.println("User home: '" + System.getProperty("user.home") + "'");
}
}
@gesellix
Copy link
Author

See also https://medium.com/redbubble/running-a-docker-container-as-a-non-root-user-7d2e00f8ee15

Your user will be $HOME-less
Your user will be nameless, too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment