Run multiple instances of PHP using Docker

Map the host port and container port. And access the PHP container outside the host network.

Bharathiraja
CodeX

--

Docker Host Port, Container Port Mapping

In this tutorial, we will see how to run multiple PHP containers using Docker on the same machine. And how to access the running PHP Docker containers outside the host computer?. Docker runs the containers in an isolated environment. So we can easily spin many new PHP containers using the docker run command. However, all the running PHP containers will use the same 80 port. Why because PHP uses port 80 for running web applications. Don’t get confused about using the same port number. Each container is running in isolated mode. So it is like a separate computer running the PHP service. So using the same port number for each container is not a problem here. Docker does not throw any errors for each container using the same port.

However, if we want to access PHP service using a browser outside of the host network, we need to give a separate port number in the host(server running on the cloud with an IP address) computer to access the container. Why because host computers do not allow us to use the same port for multiple services. So we have to map a new unique host port for each container port.

The main aim of this tutorial is how to use the port

--

--

Bharathiraja
CodeX
Writer for

AWS | DevOps | Kubernetes | Terraform| Angular | Deep&Machine Learning, Ionic, Full Stack Developer. Learn more at https://github.com/bharathirajatut