Coder Social home page Coder Social logo

Comments (18)

uburuntu avatar uburuntu commented on September 23, 2024 7

@tiangolo hello!
Now it is possible to build arm based containers on any computer. Can you support it in your scripts? If you dont have enough free time I can try to make PR.

https://medium.com/@artur.klauser/building-multi-architecture-docker-images-with-buildx-27d80f7e2408
https://collabnix.com/building-arm-based-docker-images-on-docker-desktop-made-possible-using-buildx/

from uvicorn-gunicorn-fastapi-docker.

tedivm avatar tedivm commented on September 23, 2024 5

I've made an upstream PR to make the uvicorn-gunicorn containers multiarch. Those images are on docker hub as well (since I was testing push functionality).

Assuming that gets merged I can make another PR here to do the same.

from uvicorn-gunicorn-fastapi-docker.

flyingjoe avatar flyingjoe commented on September 23, 2024 2

Since the amd64 version of this container was way too slow on my m1 mac I forked this repo and changed the deploy action to build the arm64 version aswell: https://github.com/flyingjoe/uvicorn-gunicorn-fastapi-docker/tree/ARM_Images
(same for the underlying uvicorn-gunicorn image of course)

Maybe this helps someone:
https://hub.docker.com/r/flyingjoe/uvicorn-gunicorn-fastapi

Note: I had no time yet to adapt the tests to multi platform, that's why there is no pull request yet. I wouldn't recommend using this image for production.

from uvicorn-gunicorn-fastapi-docker.

tiangolo avatar tiangolo commented on September 23, 2024 1

Yes, I would like to, that's one of the reasons why I always base these images on official ones (official Python) and use parts from official images, because these base images are multi-architecture.

The issue is that not Docker Hub automated builds nor Travis CI can compile to ARMs.

If you clone this repository, you should be able to compile the images in the Raspberry Pi itself. Although this is not ideal.

"Solution", new docs

For this specific use case, I added documentation to create your application's Dockerfile with minimal requirements, in a way compatible with Raspberry Pi.

Using only Uvicorn (without Gunicorn), to reduce resource usage.

Here's the new documentation: https://fastapi.tiangolo.com/deployment/#raspberry-pi-and-other-architectures

Future plans

One of the side-projects in my backlog is finding a way to build in ARM (Raspberry Pi) and publish in the same Docker Hub images without affecting the other architectures. And then find a way to automatize it. But I haven't been able to test it, although I actually have a small Raspberry Pi cluster/farm (8 Pis I think). But for now, I think the solution above should work.

from uvicorn-gunicorn-fastapi-docker.

mayteio avatar mayteio commented on September 23, 2024 1

+1 for multiarch!

from uvicorn-gunicorn-fastapi-docker.

ModischFabrications avatar ModischFabrications commented on September 23, 2024

Ideally the base image could be multi-architecture (https://blog.docker.com/2017/09/docker-official-images-now-multi-platform/) to maximize compatibility.

from uvicorn-gunicorn-fastapi-docker.

ModischFabrications avatar ModischFabrications commented on September 23, 2024

Thank you for your extensive answer and quick reaction, I'm even more impressed with this project. I am looking forward to your automated builds, for now I will stick to your "Solution".

I had a small problem but managed to get it working on PC using a slight modification of your newest addition to the documentation. In my case I needed to add a WORKDIR to keep my application in scope.

My new Dockerfile:

FROM python:3.7
EXPOSE 80

# manual installation
RUN pip install fastapi uvicorn

# copy whole installation (minus dockerignore)
COPY ./app /app

# install additional dependencies (might have duplicates?)
# (was pipenv previously but had problems with alpine)
COPY ./requirements.txt requirements.txt
RUN pip install -r requirements.txt

# set workdir to have subscripts in scope
WORKDIR ./app
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]

I unsuccessfully tried "improving" the Dockerfile by using FROM python:3.7-alpine. This is not possible as httpstools and uvloops are unable to build wheels. It might be sensible to empathize that as using alpine seems to be the default nowadays.

I was unable to get it running on my Raspberry Pi Zero W using the above Dockerfile. I have not found a solution in the last 2 hours, did I overlook something?

pi@modischpi-zero:~/CutSolver $ bash docker build -t cutsolver:latest .
Sending build context to Docker daemon  45.57kB
Step 1/8 : FROM python:3.7
 ---> fb676539ecfe
Step 2/8 : EXPOSE 80
 ---> Using cache
 ---> b2607ba96d8b
Step 3/8 : RUN pip install fastapi uvicorn
 ---> Running in 26bb1cd0822a
The command '/bin/sh -c pip install fastapi uvicorn' returned a non-zero code: 139

A few measurements I made while experimenting (on PC):

uvicorn-gunicorn:python3.7-alpine3.8
size: 114 554 660
init mem: 65MiB

Idle: 0.4%
Run: 7.5%

python:3.7 ("manual" build)
size: 974 971 759
init mem: 17MiB

Idle: 0.1%
Run: 7.3%

from uvicorn-gunicorn-fastapi-docker.

ModischFabrications avatar ModischFabrications commented on September 23, 2024

I was experimenting a bit and it seems like a manual build is possible on Raspberry Pi 3B, but not on Zero W. Building the image on the 3B took around 15min, but at least it's working.

The main difference was that the 3B is using ARMv7 while the Zero W has ARMv6.

from uvicorn-gunicorn-fastapi-docker.

tiangolo avatar tiangolo commented on September 23, 2024

I'm sorry for the delay. Thanks for the report. That's an interesting finding. I don't own a Zero myself, so I wouldn't know. But it seems like the issue could be right there in the ARM version difference.

from uvicorn-gunicorn-fastapi-docker.

github-actions avatar github-actions commented on September 23, 2024

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.

from uvicorn-gunicorn-fastapi-docker.

alexcombessie avatar alexcombessie commented on September 23, 2024

Interested as well!

from uvicorn-gunicorn-fastapi-docker.

assman avatar assman commented on September 23, 2024

+1 for multiarch!

from uvicorn-gunicorn-fastapi-docker.

Soneji avatar Soneji commented on September 23, 2024

@tiangolo can this be reopened please?

from uvicorn-gunicorn-fastapi-docker.

Matthieu-Tinycoaching avatar Matthieu-Tinycoaching commented on September 23, 2024

Hi @tedivm is it viable to use the arm64 docker image from your docker hub repository on production on AWS graviton? Or is it better to way for the merge?

from uvicorn-gunicorn-fastapi-docker.

tedivm avatar tedivm commented on September 23, 2024

I only put them up for testing (since docker buildx handles both building and pushing together, a registry is needed). I'm not automatically updating them or maintaining them, and after the PR is merged I plan on erasing the repo.

If you need to use these on graviton before they're merged in I'd suggest building them yourself directly, hosting on ECR, and then building off of your own images.

from uvicorn-gunicorn-fastapi-docker.

Matthieu-Tinycoaching avatar Matthieu-Tinycoaching commented on September 23, 2024

Hi @tedivm thanks but where could I find the most updated dockerfile to build these arm64 docker images?

I tried to rebuild arm64 uvicorn-gunicorn images based on https://github.com/tiangolo/uvicorn-gunicorn-docker/tree/master/docker-images and buildx, but this gave me inconsistent results unfortunately.

from uvicorn-gunicorn-fastapi-docker.

tedivm avatar tedivm commented on September 23, 2024

If you want to use images from this PR you should clone my version of the upstream repository, check out this branch, update the repository username to the one for your container repository, and then run the build and push script from that repo.

Then do the same for this repository, pointing the dockerfiles at your newly created images.

from uvicorn-gunicorn-fastapi-docker.

Matthieu-Tinycoaching avatar Matthieu-Tinycoaching commented on September 23, 2024

@flyingjoe thanks for your arm64 image on docker hub, it works well on AWS EC2 graviton.

However, I have a strange behaviour when docker is running: rapidly the docker container takes more than 2 GB of disk space. I don't understand how and why it takes so much. Do you have an idea?

Thanks!

from uvicorn-gunicorn-fastapi-docker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.