Last active
July 24, 2023 16:34
-
-
Save desaster/c0af97481b5dbeecd57286ba030715f7 to your computer and use it in GitHub Desktop.
How to run tomcat as non-root with docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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