skip to Main Content

The Azure Container Instances YAML reference gives option to expose multiple ports in the container.
see https://learn.microsoft.com/en-us/azure/container-instances/container-instances-reference-yaml

However, I haven’t figured out yet how to map/forward port as we do with docker. I would like to define on the YAML file a port forward, as we do with docker command:

docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=pw' -p 14000:1433

Is there a limitation using Azure YAML schema?

I have tried:

      ports:
      - port: 11401
      - port: 1433

but it opens both ports.

2

Answers


  1. As per the doc and doc, please try with format :

       ports:
          - "14000:1433"
    
    Login or Signup to reply.
  2. As per the below document, Azure Container Instances not supporting port mapping like in Docker.

    Please refer this doc for more details: Troubleshoot common issues – Azure Container Instances | Microsoft Learn

    The port which you expose in container instance should be same as port your container image listens to.

    However, you can achieve it by defining arguments and environment variables in the docker file which lets you overwrite port during deployment.

    For example, by default, the below docker file will listens to http port 80 as http_port is set to 80.

    #Dockerfile
    FROM TestImage
    ARG http_port=80
    ENV target_port ${http_port}
    .
    .
    .
    

    But if you require ACI to listen on different port then define target_port in the environment variables of ACI deployment yaml file as shown below.

    #Azure container instance yaml file
    
    apiVersion: ‘2021-10-01’
    location: <location-name>
    name: <container instance group name>
    properties:
         containers:
           - name: <container-name>
             properties:
                image: <image-name:version>
                environmentVariables:
                  - name: target_port
                    value: 8090 # once this environment variable defined, the port in the image will change to 8090.
              ports:
                 - port: 8090
                   protocol: tcp
          ipAddress:
              type: Public  #value can be Public or Private
              ports:
                - protocol: tcp
                  port: 8090
          type: Public
    type:Microsoft.ContainerInstance/containerGroups
    

    Once the above has file has deployed, Azure Container Instance starts listen to port 8090 even image port is 80.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search