Docker Community Forums

Share and learn in the Docker community.

How to change a apache port dynamically in Dockerfile

I am Having a docker file for installing apache on ubuntu:16.04. Apache default port number s 80.

As per my requirement i need to change port 80 to some other port like 9090.

Please let me know what command i need to mention in the dockerfile for changing the port to 9090

1 Like

You could change the listening port of the Apcache in /etc/apache2/ports.conf (depending on OS). BUT this Apache instance would just run inside the docker container and will not automatically be reachable on this port from the outside (host). You can set the listening port to whatever you like, but it’s the “port-mapping” between the host and the container that is crucial.
So leave the apache running on port 80 and change the port-mapping when launching the container:

docker run --name myApache1 -p 9090:80 -d < ID of Apache Image>

This docker run will start an Apache Image and map the port 9090 on the host to port 80 inside the container.