Reputation: 2477
I'm trying to deploy an api with fastapi
with docker on a server with nginx
as a reversed proxy.
This is my Dockerfile:
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.6
RUN mkdir /srv/app
ENV SEGPKG=/srv/app
COPY . $SEGPKG
WORKDIR /srv/app
RUN pip install --upgrade pip --proxy my_proxy --trusted-host pypi.python.org
RUN pip install -e $SEGPKG --proxy my_proxy
EXPOSE 80
CMD ["gunicorn","--timeout","90","--log-level","error", "--reload", "-b", "0.0.0.0:80","--worker-class=uvicorn.workers.UvicornH11Worker", "--workers=24", "app.main:app"]
and everything is handled by a docker-compose
. Nginx is already installed on my server.
The deployment is ok: i can access my api, make a request and recieve a response.
By chanche yesterday, I ran top
on my linux centos server and i saw this:
3369 root 20 0 582388 338624 6016 S 0.7 1.0 0:46.62 gunicorn
3389 root 20 0 582388 338460 5792 S 0.7 1.0 0:46.40 gunicorn
3382 root 20 0 582388 338428 5800 S 0.7 1.0 0:46.45 gunicorn
3356 root 20 0 582392 338408 5788 S 0.7 1.0 0:46.24 gunicorn
3355 root 20 0 582392 338400 5788 S 0.3 1.0 0:46.86 gunicorn
3424 root 20 0 582392 338388 5792 S 0.3 1.0 0:45.80 gunicorn
3344 root 20 0 582392 338384 5796 S 0.7 1.0 0:46.26 gunicorn
3413 root 20 0 582392 338384 5788 S 0.3 1.0 0:46.52 gunicorn
3341 root 20 0 582404 338376 5836 S 0.3 1.0 0:46.10 gunicorn
3348 root 20 0 582392 338372 5792 S 0.7 1.0 0:46.38 gunicorn
3402 root 20 0 582392 338360 5788 S 0.7 1.0 0:46.15 gunicorn
3401 root 20 0 582392 338344 5796 S 0.3 1.0 0:46.24 gunicorn
3422 root 20 0 582392 338344 5788 S 0.3 1.0 0:46.75 gunicorn
3351 root 20 0 582392 338336 5788 S 1.0 1.0 0:46.47 gunicorn
3359 root 20 0 582392 338316 5788 S 0.7 1.0 0:46.48 gunicorn
3399 root 20 0 582388 338312 5788 S 0.3 1.0 0:46.01 gunicorn
3408 root 20 0 582392 338312 5788 S 0.7 1.0 0:46.38 gunicorn
3421 root 20 0 582392 338312 5788 S 0.3 1.0 0:46.08 gunicorn
3343 root 20 0 582396 338304 5812 S 0.7 1.0 0:45.97 gunicorn
3360 root 20 0 582392 338296 5788 S 0.7 1.0 0:46.43 gunicorn
3397 root 20 0 582388 338288 5788 S 0.3 1.0 0:46.49 gunicorn
3425 root 20 0 582392 338260 5792 S 0.3 1.0 0:46.42 gunicorn
3345 root 20 0 582392 338204 5792 S 0.7 1.0 0:45.63 gunicorn
3353 root 20 0 582392 338160 5788 S 0.7 1.0 0:46.59 gunicorn
Then i went to the docker container created for serving this api and ran top
1 root 20 0 36000 23116 5092 S 0.0 0.1 0:01.32 gunicorn
8 root 20 0 582404 338376 5836 S 0.0 1.0 0:47.97 gunicorn
10 root 20 0 582396 338304 5812 S 0.0 1.0 0:47.91 gunicorn
11 root 20 0 582392 338384 5796 S 0.0 1.0 0:48.17 gunicorn
12 root 20 0 582392 338204 5792 S 0.0 1.0 0:47.55 gunicorn
15 root 20 0 582392 338372 5792 S 0.0 1.0 0:48.25 gunicorn
18 root 20 0 582392 338336 5788 S 0.0 1.0 0:48.35 gunicorn
20 root 20 0 582392 338160 5788 S 0.0 1.0 0:48.52 gunicorn
22 root 20 0 582392 338400 5788 S 0.0 1.0 0:48.77 gunicorn
23 root 20 0 582392 338408 5788 S 0.0 1.0 0:48.19 gunicorn
26 root 20 0 582392 338316 5788 S 0.0 1.0 0:48.36 gunicorn
27 root 20 0 582392 338296 5788 S 0.0 1.0 0:48.33 gunicorn
36 root 20 0 582388 338624 6016 S 0.0 1.0 0:48.51 gunicorn
43 root 20 0 582388 338428 5800 S 0.0 1.0 0:48.34 gunicorn
48 root 20 0 582388 338460 5792 S 0.0 1.0 0:48.31 gunicorn
53 root 20 0 582388 338288 5788 S 0.0 1.0 0:48.38 gunicorn
54 root 20 0 582388 338312 5788 S 0.0 1.0 0:47.92 gunicorn
56 root 20 0 582392 338344 5796 S 0.0 1.0 0:48.14 gunicorn
57 root 20 0 582392 338360 5788 S 0.0 1.0 0:48.07 gunicorn
63 root 20 0 582392 338312 5788 S 0.0 1.0 0:48.27 gunicorn
68 root 20 0 582392 338384 5788 S 0.0 1.0 0:48.46 gunicorn
75 root 20 0 582392 338312 5788 S 0.0 1.0 0:48.01 gunicorn
76 root 20 0 582392 338344 5788 S 0.0 1.0 0:48.68 gunicorn
78 root 20 0 582392 338388 5792 S 0.0 1.0 0:47.71 gunicorn
79 root 20 0 582392 338260 5792 S 0.0 1.0 0:48.35 gunicorn
Gunicorn is only used by this application. I really don't get it.
It seems that gunicorn master is spawning workers in the host as well as in the docker container? It doesn't make sense to me.
If i'm wrong an explaination would really help.
Thanks
Upvotes: 1
Views: 489
Reputation: 523
Not a Linux expert, but I was curious and found this SO question, not related to gunicorn
, but still about docker processing being shown in the host.
Basically it's intended to be that way. Docker is NOT a virtual machine, the container processes are run by the same operating system / kernel of the host and thus are visible there.
Upvotes: 2