Trying to create an Azure Multi-Container App with Two Ports Exposed

65 Views Asked by At

In my use case, I am trying to run a multi-container app where each container will have its own port (one of the containers/ports is for uploading files in a separate thread). I could break this up into 2 different containers, but I am trying to avoid that. I have spent a week trying different techniques - I am hoping that someone can point me in the right direction.

I can see that Azure "Web App" allows for multi-containers, but the limitation here is that does not allow for custom ports.
I can see that Azure Container apps allow for custom ports, but in the setup you need to specify a single image.

Here is my docker-compose.

version: '3.8'

volumes:
  db-data:
  uploads:

services:
  redis:
    image: redis:alpine
    ports:
      - '6379:6379'

  python-server:
    image: <custom image name>:latest
    privileged: true
    build:
      context: .
      dockerfile: dockerfile
    working_dir: /
    ports:
      - '8080:8080'
      - '8050:8050'
    env_file: .env
    volumes:
      - db-data:/instance/
      - uploads:/persistence/uploads/ 

In my Dockerfile I am trying to expose 8050 for the uploads:

FROM python:3.11

WORKDIR /

# Install dependencies
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

# Copy your application code
COPY . .

VOLUME /instance/
VOLUME /persistence/uploads/

# Expose ports 
EXPOSE 8080
EXPOSE 8050

# Run the server command
CMD ["./run-app.sh"]
2

There are 2 best solutions below

0
Suresh Chikkam On

I can see that Azure "Web App" allows for multi-containers, but the limitation here is that does not allow for custom ports.

Azure Web App for Containers doesn't allow you to specify custom ports for individual containers within a multi-container setup. It automatically maps the exposed ports of your containers to the default HTTP port 80 (or HTTPS port 443 if SSL is enabled).

  • Application relies on custom port mappings for specific functionality, Then Azure Web App for Containers might not be the best approach, Instead, you would need to explore other Azure Container Instances

Create an Azure Container Registry where you'll store your Docker images.

enter image description here

Create a configuration file that describes your multi-container application. In this file, specify the details of your containers

aci.yaml :

apiVersion: '2019-12-01'
location: <Your Azure Region>
name: <Your ACI Name>
properties:
  containers:
    - name: redis-container
      properties:
        image: redis:alpine
        ports:
          - port: 6379
    - name: python-server-container
      properties:
        image: <ACR URL>/<custom image name>:latest
        ports:
          - port: 8080
          - port: 8050
  osType: Linux
  restartPolicy: Always
  • Here, I deployed the aci.yaml file through CLI.

enter image description here

After deployment, to access the ports exposed by the Azure Container Instances (ACI), we can use the public IP address assigned to your ACI instance along with the specified port numbers.

enter image description here

  • Use the IP address 20.9.120.152 along with port 8080 to access the Python server: http://20.9.120.152:8080.
  • Use the IP address 20.9.120.152 along with port 8050 to access the File upload functionality: http://20.9.120.152:8050.
0
AdamCodes716 On

Thank you @suresh Chikkam, that looks like a valid solution. I had actually gone in a different direction by the time that I saw your post. I removed docker compose entirely and instead installed redis in dockerfile using code. This allowed me to make the app into a single container app. Once I had that, I was able to use a Container App and then use a little powershell to open the additional external ports as per the documentation. From Dockerfile: RUN apt-get update && apt-get install -y redis-server