Skip to content

Instantly share code, notes, and snippets.

@desaster
Last active July 24, 2023 16:34
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save desaster/c0af97481b5dbeecd57286ba030715f7 to your computer and use it in GitHub Desktop.
Save desaster/c0af97481b5dbeecd57286ba030715f7 to your computer and use it in GitHub Desktop.
How to run tomcat as non-root with docker
#
# How to run tomcat as non-root with docker
#
# We want to map the tomact process to host user, which is created here
sudo useradd -r docker-tomcat
# start a container, but don't run tomcat yet
docker run -it -d --name=tomcat-intermediate -u $(id docker-tomcat -u) tomcat:8.0 /bin/sh
# while the container is running /bin/sh, fix permissions as root
docker exec -it -u root tomcat-intermediate chown -R $(id docker-tomcat -u) /usr/local/tomcat
# commit changes to a new image
docker commit tomcat-intermediate tomcat-fixed
# permissions are fixed, let's stop the container
docker stop tomcat-intermediate
# and remove the container
docker rm tomcat-intermediate
# create and start the container using the new image which has the proper permissions
docker create --name=tomcat-test1 -u $(id docker-tomcat -u) tomcat-fixed catalina.sh run docker start -a tomcat-test1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment