My Dockerfile I uplaod to azure container registries or using docker hub times out or has issues pulling the docker file. I'm using Azure web app to run a flask based website. My setup is this. I'm using a docker-linux file with a python 3.11 based flask website. its configured to run on port 80 on 0.0.0.0. I also am using the free or basis tier. my web app sets up the container just fun but will time out or not pull the docker image. is this because the dockerfile is not windows based or what am I missing:
# --- Stage 1: Install dependencies in a temporary build image ---
FROM python:3.11-slim AS builder
# Set working directory inside the container
WORKDIR /app
# Install system dependencies for WeasyPrint
RUN apt-get update && apt-get install -y \
build-essential \
libpango1.0-0 \
libcairo2 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libffi-dev \
libxml2 \
libxslt1-dev \
zlib1g \
gir1.2-pango-1.0 \
gir1.2-glib-2.0 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Copy only requirements file to install dependencies
COPY requirements.txt /app/
# Install Python dependencies in a virtual environment for efficiency
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
# --- Stage 2: Create the final container with only necessary files ---
FROM python:3.11-slim
# Set working directory inside the container
WORKDIR /app
# Install runtime dependencies for WeasyPrint
RUN apt-get update && apt-get install -y \
libpango1.0-0 \
libcairo2 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libffi-dev \
libxml2 \
libxslt1-dev \
zlib1g \
gir1.2-pango-1.0 \
gir1.2-glib-2.0 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Copy installed dependencies from the builder stage
COPY --from=builder /install /usr/local
# Copy the entire application into the container
COPY . /app
# Ensure Python finds our modules
ENV PYTHONPATH=/app
# Expose the port Flask will run on
EXPOSE 80
# Set environment variables (Optional but recommended)
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
ENV FLASK_ENV=production
# Run the Flask app with Gunicorn for production
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:80", "app:app"]
My Dockerfile I uplaod to azure container registries or using docker hub times out or has issues pulling the docker file. I'm using Azure web app to run a flask based website. My setup is this. I'm using a docker-linux file with a python 3.11 based flask website. its configured to run on port 80 on 0.0.0.0. I also am using the free or basis tier. my web app sets up the container just fun but will time out or not pull the docker image. is this because the dockerfile is not windows based or what am I missing:
# --- Stage 1: Install dependencies in a temporary build image ---
FROM python:3.11-slim AS builder
# Set working directory inside the container
WORKDIR /app
# Install system dependencies for WeasyPrint
RUN apt-get update && apt-get install -y \
build-essential \
libpango1.0-0 \
libcairo2 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libffi-dev \
libxml2 \
libxslt1-dev \
zlib1g \
gir1.2-pango-1.0 \
gir1.2-glib-2.0 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Copy only requirements file to install dependencies
COPY requirements.txt /app/
# Install Python dependencies in a virtual environment for efficiency
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
# --- Stage 2: Create the final container with only necessary files ---
FROM python:3.11-slim
# Set working directory inside the container
WORKDIR /app
# Install runtime dependencies for WeasyPrint
RUN apt-get update && apt-get install -y \
libpango1.0-0 \
libcairo2 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libffi-dev \
libxml2 \
libxslt1-dev \
zlib1g \
gir1.2-pango-1.0 \
gir1.2-glib-2.0 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Copy installed dependencies from the builder stage
COPY --from=builder /install /usr/local
# Copy the entire application into the container
COPY . /app
# Ensure Python finds our modules
ENV PYTHONPATH=/app
# Expose the port Flask will run on
EXPOSE 80
# Set environment variables (Optional but recommended)
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
ENV FLASK_ENV=production
# Run the Flask app with Gunicorn for production
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:80", "app:app"]
The issue you're facing is related to the Azure Free Tier.
Standard or premium
App Service plan.I got the same issue when deploying the application using your dockerfile, so I've upgraded my pricing tier to Premimum
.
App.js:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello, Azure Web App with Docker!"
if __name__ == "__main__":
import os
port = int(os.environ.get("PORT", 8080))
app.run(host="0.0.0.0", port=port)
docker build -t <ImageName> .
docker tag <ImageName> <AzureContainerRegistryName>.azurecr.io/<Imagename>:<tagName>
docker push <AzureContainerRegistryName>.azurecr.io/<ImageName>:<tagName>
Now I've successfully deployed my application to Azure Web App without any issues.