Download and unpack a Tomcat8 distribution. Lets say the location is /usr/local/tomcat8.
First, we will create a self-signed certificate using the java keytool. This is the command:
keytool -genkey -noprompt -trustcacerts -keyalg RSA -alias tomcat -dname "CN=Palash Ray, OU=Demo, O=Swayam, L=Bangalore, ST=Karnataka, C=IN" -keypass changeme -keystore /usr/local/tomcat8/keystore/my_keystore -storepass changeme
This will create the keypair at the location /usr/local/tomcat8/keystore/my_keystore.
Now, go to the /usr/local/tomcat8/conf directory. In the server.xml, look for commented lines:
Uncomment that and replace it with:
You should be all set now. Save the server.xml and start tomcat. Go to: https://localhost:8443
This can be embedded into a docker image. This is how the docker file would look:
FROM tomcat:8.5 RUN mkdir "$CATALINA_HOME/keystore" RUN keytool -genkey -noprompt -trustcacerts -keyalg RSA -alias tomcat -dname "CN=Palash Ray, OU=Demo, O=Swayam, L=Bangalore, ST=Karnataka, C=IN" -keypass changeme -keystore "$CATALINA_HOME/keystore/my_keystore" -storepass changeme COPY server.xml "$CATALINA_HOME/conf/server.xml" EXPOSE 8443
The sources can be found here:
https://github.com/paawak/blog/tree/master/code/apache-http-client/src/main/docker
The docker image can be found here:
https://hub.docker.com/r/paawak/self-signed-tomcat8/
You can run the image by using:
docker pull paawak/self-signed-tomcat8
docker run -d -p 9090:8443 paawak/self-signed-tomcat8