admin管理员组文章数量:1417061
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"]
Share
Improve this question
edited Feb 14 at 19:41
Amit Verma
9,6048 gold badges37 silver badges41 bronze badges
asked Feb 3 at 1:00
FrosyFeet456FrosyFeet456
3492 silver badges12 bronze badges
4
- As you're using Free or Basic tier, These have limitations that might cause timeouts. Try upgrading to standard or premium. – Sirra Sneha Commented Feb 3 at 3:38
- What is the error message when the pull request fails? – Sirra Sneha Commented Feb 3 at 3:39
- What does you're azure app service log stream show? – Sirra Sneha Commented Feb 3 at 3:41
- The issue could be because the Free tier has limited resources, causing slowdowns or timeouts if there are too many users. It might also take longer to start after being idle. If your Flask app isn't set up right (like the wrong port or not binding to 0.0.0.0). – Sirra Sneha Commented Feb 5 at 10:59
1 Answer
Reset to default 0The issue you're facing is related to the Azure Free Tier.
- Since you're installing many dependencies like WeasyPrint may need more memory, the Free Tier has limited CPU, memory, and storage, which may cause the container to fail during installation or execution of these dependencies.
- Please refer this doc for better understanding about Azure App Service plans.
- To resolve the issue, move to a
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)
- Run the below commands to build and push image to Azure container registry.
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.
本文标签: flaskAzure web app can39t pull docker image or times outStack Overflow
版权声明:本文标题:flask - Azure web app can't pull docker image or times out - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745252646a2649915.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论