Why is my App Service for Linux container not responding on port 8000 and showing "Operation was canceled" in logs?

Javier 40 Reputation points
2025-05-09T20:29:36.45+00:00

I'm deploying a custom Python 3.11 container with Flask and Gunicorn to Azure App Service for Linux using GitHub Actions. The app binds to 0.0.0.0:8000 and works fine locally and in another Azure App Service instance. However, in this instance:

  • Requests result in error logs:
      System.IO.IOException: Unable to read data from the transport connection: Operation canceled. System.Net.Sockets.SocketException (125): Operation canceled
    
    SSH access fails with SSH CONN CLOSE in Azure Portal curl http://localhost:8000/ from Kudu returns connection refused No files visible under /home/site/wwwroot via Kudu shell My ENTRYPOINT script starts both sshd and gunicorn main:app -b 0.0.0.0:8000

App logs indicate the Flask app starts and runs, but requests don't get through. There are no disk or memory issues.

Ask: Can you help identify why the container is not responding on port 8000 despite Gunicorn starting, and why both HTTP and SSH access are failing?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,933 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Siva Nair 2,420 Reputation points Microsoft External Staff Moderator
    2025-05-09T21:32:15.99+00:00

    Hi Javier,

    Lets troubleshoot with few points below:

    1. By default, Azure App Service expects your container to listen on port 80. Since your Flask app is set to listen on port 8000, you'll need to configure the WEBSITES_PORT application setting. You can do this through Azure CLI with the following command:
         az webapp config appsettings set --resource-group <group-name> --name <app-name> --settings WEBSITES_PORT=8000
      
      Make sure to replace <group-name> and <app-name> with your actual resource group and app names.
    2. The error message indicating "Operation was canceled" often points to issues with connectivity or resource limits. Since you're also having trouble with SSH access, check that the sshd service is indeed running properly in your container. If you can't access SSH, ensure your ENTRYPOINT script is correctly launching sshd before starting Gunicorn. Update ENTRYPOINT Script Ensure it ends with:
         /usr/sbin/sshd &
         exec gunicorn main:app -b 0.0.0.0:8000
      
    3. Ensure your Dockerfile correctly exposes port 8000. You might need an EXPOSE 8000 line in your Dockerfile.
    4. Since you mentioned the logs show your Flask app starts, but you are getting "connection refused" using curl through Kudu, ensure your Flask application is binding correctly to 0.0.0.0:8000 within the container.
    5. Review the network settings and access restrictions to ensure that nothing is blocking requests to your container.

    You may refer to the blog Things You Should Know: Web Apps and Linux for more details on this.

    If you have any further assistant, do let me know.

    0 comments No comments

  2. Kantamsetti Aslesha 250 Reputation points Microsoft External Staff
    2025-05-19T12:35:31.6+00:00

    Hi @Javier
    Double-check container logs via the Log Stream or az webapp log tail to confirm whether Gunicorn is binding to 0.0.0.0:8000 and staying alive after startup.

    Temporarily remove sshd from your ENTRYPOINT script to rule out conflicts or startup failures. This can help determine if SSH is interfering with the container startup process.

    1. Use exec properly in ENTRYPOINT — ensure Gunicorn is launched with exec so it replaces the shell and Azure sees the app process:
         
         /usr/sbin/sshd &
      

    exec gunicorn main:app -b 0.0.0.0:8000

       
    1. **Ensure your image exposes port 8000**:
    
       ```dockerfile
       
       EXPOSE 8000
    

    Verify runtime compatibility — If this App Service instance uses a different Linux distro or App Service Plan tier than the one that works, try aligning them. Differences in OS or restrictions can cause unexpected behavior.

    Try binding to port 80 as a test (and update WEBSITES_PORT accordingly), in case port 8000 is somehow blocked or misconfigured.

    If possible, please also confirm whether you see any output when testing the image locally with:

    
    docker run -p 8000:8000 yourimage
    curl http://localhost:8000
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.