Skip to content
Advertisement

How to stop uvicorn ASGI web server running when building Dockerfile?

Docker build running endlessly

I’m trying to build a docker image, but i’m running into an issue with uvicorn server running while building which causes it to never build.

so i’m looking for an alternative way of building/running the docker image.

Required the docker image should run the uvicorn server on startup

Haven’t found any real solution from browsing SOF/Google

Code

main.py file

JavaScript

Dockerfile

JavaScript

Console output

JavaScript

Advertisement

Answer

Use CMD instead of RUN to launch the uvicorn server in the Dockerfile. It will retard the execution of the command to when the container is launched.

RUN runs commands during the image building.

CMD runs commands during container launching.

Your Dockerfile would be rewritten as follows:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement