Methods of payment Abuse

What are container ports?

10.09.2023, 23:08

Container ports are specific network ports that can be bound to specific services or applications inside the container.

What is the feature of containers

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.

ports:
external_port:internal port

For example, we will 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 via the appropriate port. Users can interact with the application by accessing the container port that has been forwarded to the host machine.

How to launch a container

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:

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> 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:

docker run -p 8080:80 nginx

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:

docker run -p 8080-8082:80-82 nginx

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.