How to change the Tomcat port from 8080 to 80 in a Dockerfile

Problem:

I am using tomcat:alpine as my base image in my Dockerfile but I want to run Tomcat on port 80 not 8080.

Solution:

Add the following line to your Dockerfile:

RUN value=`cat conf/server.xml` && echo "${value//8080/80}" >| conf/server.xml

Explanation:

I am sure many of you are wondering why I did not use –p 80:8080 in my Docker run command. Because I am not issuing a run command. I am using the new Azure Container Instances that I spun up using an Azure Resource Manager template. The instance is running in a Container Group and they do not support port mapping. Therefore, I had to change the port Tomcat exposes.

Add comment

Loading