When running container in container with arbitrary user id but you want a proper uid to perform task like git pull or any runnable container task.
User nss_wrapper
in Dockerfile
yum install nss_wrapper
.....
command ["./startup.sh"]
in startup.sh
.....
function generate_passwd_file() {
USER_ID=$(id -u)
GROUP_ID=$(id -g)
if [ x"$USER_ID" != x"0" -a x"$USER_ID" != x"997" ]; then
NSS_WRAPPER_PASSWD=passwd
NSS_WRAPPER_GROUP=/etc/group
cp /etc/passwd $NSS_WRAPPER_PASSWD
echo "default:x:${USER_ID}:${GROUP_ID}:Default:${HOME}:/sbin/nologin" >> $NSS_WRAPPER_PASSWD
export NSS_WRAPPER_PASSWD
export NSS_WRAPPER_GROUP
export LD_PRELOAD=libnss_wrapper.so
fi
}
generate_passwd_file
exec java -jar something.jar
- https://docs.openshift.com/enterprise/3.1/creating_images/guidelines.html
- http://developers.redhat.com/blog/2015/05/05/testing-your-software-stack-without-root-privileges-using-cwrap/
- http://blog.dscpl.com.au/2015/12/unknown-user-when-running-docker.html
- https://cwrap.org/
- https://github.com/openshift/jenkins/blob/36012a7d03018d7a6800b940a7ed2c467fb884a1/1/contrib/jenkins/jenkins-common.sh#L13