Container ports are specific network ports that can be bound to specific services or applications within the container.
Each container can have its own ports that can be used to communicate with the outside world or to communicate with other containers. When starting a container, you can specify which ports should be available inside the container and which ports should be forwarded to the host machine.
ports:
external_port:Internal port
For example, let's forward port 80 as 8094:
docker-nginx:
image: nginx
ports:
- '8094:80'
When the container is running, the application inside the container can listen or send data through the appropriate port. Users can interact with the application by accessing the container port that was forwarded to the host machine.
To start container ports, you will need to use the docker run
command with the -p
or --publish
flag.
The syntax for the docker run command with the -p
flag is as follows:
docker run -p <host port>:<container port> <image_name>
Where:
<host-port> is the port on your host that will be proxied to the container port.
<container-port> - the port within the container that will be reachable through the specified host port.
<image_name> - the name of the container image 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:
docker run -p 8080:80 nginx
The web server running in the container will now be accessible on port 8080 of your host.
You can also use a port range by specifying multiple <host-port>:<container-port> pairs.
For example:
docker run -p 8080-8082:80-82 nginx
This will proxy ports 80, 81, and 82 within the container to ports 8080, 8081, and 8082 of your host, respectively. Once you start the container with the 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: