AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.
Port mappings allow containers to access ports on the host container instance to send or receive traffic. Port mappings are specified as part of the container definition.
If you use containers in a task with the awsvpc
or host
network mode,
specify the exposed ports using containerPort
. The hostPort
can be left
blank or it must be the same value as the containerPort
.
Most fields of this parameter (containerPort
, hostPort
, protocol
)
maps to PortBindings
in the docker container create command and the --publish
option to docker run
. If the network mode of a task definition is set to host
,
host ports must either be undefined or match the container port in the port mapping.
You can't expose the same container port for multiple protocols. If you attempt this, an error is returned.
After a task reaches the RUNNING
status, manual and automatic host and container
port assignments are visible in the networkBindings
section of DescribeTasks
API responses.
Namespace: Amazon.ECS.Model
Assembly: AWSSDK.ECS.dll
Version: 3.x.y.z
public class PortMapping
The PortMapping type exposes the following members
Name | Description | |
---|---|---|
![]() |
PortMapping() |
Name | Type | Description | |
---|---|---|---|
![]() |
AppProtocol | Amazon.ECS.ApplicationProtocol |
Gets and sets the property AppProtocol. The application protocol that's used for the port mapping. This parameter only applies to Service Connect. We recommend that you set this parameter to be consistent with the protocol that your application uses. If you set this parameter, Amazon ECS adds protocol-specific connection handling to the Service Connect proxy. If you set this parameter, Amazon ECS adds protocol-specific telemetry in the Amazon ECS console and CloudWatch. If you don't set a value for this parameter, then TCP is used. However, Amazon ECS doesn't add protocol-specific telemetry for TCP.
Tasks that run in a namespace can use short names to connect to services in the namespace. Tasks can connect to services across all of the clusters in the namespace. Tasks connect through a managed proxy container that collects logs and metrics for increased visibility. Only the tasks that Amazon ECS services create are supported with Service Connect. For more information, see Service Connect in the Amazon Elastic Container Service Developer Guide. |
![]() |
ContainerPort | System.Int32 |
Gets and sets the property ContainerPort. The port number on the container that's bound to the user-specified or automatically assigned host port.
If you use containers in a task with the
If you use containers in a task with the |
![]() |
ContainerPortRange | System.String |
Gets and sets the property ContainerPortRange. The port number range on the container that's bound to the dynamically mapped host port range.
The following rules apply when you specify a
You can call |
![]() |
HostPort | System.Int32 |
Gets and sets the property HostPort. The port number on the container instance to reserve for your container.
If you specify a
If you use containers in a task with the
If you use containers in a task with the
The default ephemeral port range for Docker version 1.6.0 and later is listed on the
instance under
The default reserved ports are 22 for SSH, the Docker ports 2375 and 2376, and the
Amazon ECS container agent ports 51678-51680. Any host port that was previously specified
in a running task is also reserved while the task is running. That is, after a task
stops, the host port is released. The current reserved ports are displayed in the
|
![]() |
Name | System.String |
Gets and sets the property Name.
The name that's used for the port mapping. This parameter is the name that you use
in the |
![]() |
Protocol | Amazon.ECS.TransportProtocol |
Gets and sets the property Protocol.
The protocol used for the port mapping. Valid values are |
.NET:
Supported in: 8.0 and newer, Core 3.1
.NET Standard:
Supported in: 2.0
.NET Framework:
Supported in: 4.5 and newer, 3.5