Search code examples
amazon-web-servicesdockeramazon-ecs

`containerPort` and `hostPort`, which one is used by the web application internally and which one is seen by the outside?


I found the following task definiation of ECS task, which is a web application. As for containerPort and hostPort, which one is used by the web application internally and which one is used by the outside of the docker for accessing the page?

'taskDefinition': {
    'compatibilities': ['EC2'],
    'containerDefinitions': [{
        'portMappings': [{
            'containerPort': 4041,
            'hostPort': 4090,
            'protocol': 'tcp'}],

Solution

  • containerPort is the port that the container exposes. hostPort is the port you want to map it to on the host. You can use the same port on both to make things simpler.

    https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_PortMapping.html