- Python(muffin, uvicorn, gunicorn): https://hub.docker.com/r/horneds/muffin
- Same + NodeJS: https://hub.docker.com/r/horneds/muffin-node
Docker image with Muffin managed by Gunicorn
- muffin:py38, muffin-node:py38
- muffin:py39, muffin-node:py39
- muffin:py310, muffin-node:py310
- muffin:py311, muffin:latest, muffin-node:py311, muffin-node:latest
- You don't need to clone the GitHub repo. You can use this image as a base image for other images, using this in your
Dockerfile
:
FROM horneds/muffin:latest
COPY ./app /app
It will expect a file at /app/app.py
.
Or otherwise a file at /app/main.py
.
And will expect it to contain a variable app
with your "ASGI" application.
Then you can build your image from the directory that has your Dockerfile
, e.g:
docker build -t myimage ./
- Run a container based on your image:
docker run -d --name mycontainer -p 80:80 myimage
You should be able to check it in your Docker container's URL, for example: http://127.0.0.1/ (or equivalent, using your Docker host).
You will probably also want to add any dependencies for your app and pin them to a specific version, probably including Uvicorn and Gunicorn.
This way you can make sure your app always works as expected.
You could install packages with pip
commands in your Dockerfile
, using a
requirements.txt
, or even using Poetry.
Here's a small example of one of the ways you could install your dependencies making sure you have a pinned version for each package.
Let's say you have a your dependencies in a file requirements.txt
.
Then you could have a Dockerfile
like:
FROM horneds/muffin:latest
# Copy and install dependencies
COPY ./requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
COPY ./app /app
That will:
- Copy your application requirements.
- Install the dependencies.
- Then copy your app code.
-
MODULE_NAME (
app
,main
,app.app
,app.main
) -- python module that contains Muffin application -
VARIABLE_NAME (
app
) -- The variable inside of the Python module that contains the Muffin application -
SETUP_SCRIPT -- Optional setup script to run before start gunicorn
-
GWORKER_CLASS (
uvicorn.workers.UvicornWorker
) -- Gunicorn Worker Class -
GWORKERS (
num of CPU
) -- Number of gunicorn workers -
HOST (
0.0.0.0
) -- Host to bind the server -
PORT (
80
) -- Port to bind the server -
GBIND (
0.0.0.0:80
) -- Address (host:port) to bind the server inside the container. If the variable is set, the variables$HOST
,$PORT
will be ignored. -
GLOG_LEVEL (
info
) -- Gunicorn log level -
GUNICORN_CMD_ARGS -- Optional Gunicorn command arguments
This project is licensed under the terms of the MIT license.