Container ports are specific network ports that can be bound to specific services or applications inside the container.
Each container can have its own ports that can be used to communicate with the outside world or to interact with other containers. When starting the container, you can specify which ports should be available inside the container and which ports should be forwarded to the host machine.
For example, we will forward port 80 as 8094:
When the container is running, the application inside the container can listen or send data via the appropriate port. Users can interact with the application by accessing the container port that has been forwarded to the host machine.
To run the container ports, you will need to use the docker run command with the -p or --publish flag.
The syntax of the docker run command with the -p flag looks like this:
Where:
<host port> is the port on your host that will be proxied to the container port.
<container port> is the port inside the container that will be accessible via the specified host port.
<image_name> is the name of the container image that you want to run.
For example, to start a container with a web server on port 80 and proxy it to port 8080 of your host, you can use the following command:
Now the web server running in the container will be accessible via port 8080 of your host.
You can also use a range of ports by specifying multiple <host-port> pairs:<container-port>. For example:
This proxies ports 80, 81 and 82 inside the container to ports 8080, 8081 and 8082 of your host, respectively. After launching a container with proxied ports, you will be able to access them through the specified host ports.
Apply the discount by inserting the promo code in the special field at checkout: