Docker Port Forwarding
Port forwarding is a process to redirect the communication of one address to other.
It is also known as Port Binding.
We can use
command to use port forwarding in our local Docker environment.
docker run -p 8000:8000 django-app
The first port number is the local machine port and followed by a
is the container port number.
SO, the request from the container port are forwarded to the local/outside world in the docker environment.
Additionally, we need to expose the container port first. We can do that in the Dockerfile or by adding a
argument followed by the port to expose. This will open the port on container to forward the requests to the specified port in the
In the Dockerfile, we can expose the port by adding the command
, or any other port number.