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.

Comments (4) -

  • Joachim Aumann

    5/15/2018 8:14:37 AM | Reply

    this has not worked for me.

    Using this was successfull:
    RUN sed -i 's/port="8080"/port="80"/' /usr/local/tomcat/conf/server.xml

    • Erick

      1/24/2019 11:16:10 PM | Reply

      sed or value change dependent on the OS. Should not mark down as he specified the specific OS in use.

  • Mitrakov

    5/13/2020 8:54:35 PM | Reply

    Joachim Aumann, thanks! Your command works for me:
    RUN sed -i 's/port="8080"/port="80"/' /usr/local/tomcat/conf/server.xml

  • Srini

    12/17/2020 5:07:19 PM | Reply

    The below command worked for me thanks for posting.

    RUN sed -i 's/port="8080"/port="80"/' /usr/local/tomcat/conf/server.xml

Add comment

Loading