Building TensorFlow AI from source in a container
Introduction
I wanted to get into the container mindset and start messing around with TensorFlow (TF). Whilst this can be done with Docker, I knew that if I had access to a Fedora/CentOS/RHEL/Oracle Linux distro with a fairly recent kernel I would get my "money's worth" in also getting a daemonless OCI-compliant build and runtime system going. I also wanted to get more experience with Bazelisk to manage my Bazel version.
Writing the Dockerfile
a) I downloaded the master PEM certificate I used to browse the Bazel releases page. As of writing I found it at https://releases.bazel.build/ and saved it as bcr-bazel-build.pem
b) I cloned TF, created a directory called certs, and placed my PEM inside it
c) I also created a Dockerfile:
I chose Debian bookworm (I recommmend checking the latest version, this may be outdated by the time you read this) instead of the alpine image because I knew that there were issues with musl libc. And I'm grateful to Snyk for highlighting security vulnerabilities that I never thought about.
I then created a directory called buildmachine, and installed Bazelisk. The PEM certificate was added to the certificate store via the root account. I then created and activated an unprivileged user account, copied the entire TF directory over, compiled TF and created an interactive Bash shell entrypoint for which I could then use later on.
Container time
To build the image, I made sure I had buildah and podman available:
I then built the image like so:
I wanted to familiarise myself with generating OCI and Docker images using one tool hence Buildah was a natural choice.
I was really overjoyed that it worked. Glory and praise to my God, Jesus for the ability to have this thing working. To test it out, I used podman to run the local container:
And to clean up everything, I ran podman again:
I know that this is just the starting point. I don't recommend it for production systems yet, but I think it's a nice little POC that met all my goals stated above.
Thanks for reading!
The advice and information provided is general in nature only and has been prepared without taking account of your particular objectives, financial situation or needs. You should, before acting on any advice or information, consider the appropriateness of the advice or information, having regard to your objectives, financial situation and needs. If you are considering acquiring a financial product, you should obtain and review its product disclosure statement before making any decision about whether to acquire the product. Past performance is not a reliable indicator of future performance.
Bible lover. Founder at Zingrevenue. Insurance, coding and AI geek.
1yWe have liftoff! 🚀
Bible lover. Founder at Zingrevenue. Insurance, coding and AI geek.
1y"Dogfooding" (testing the build with my own advice 😁)
Bible lover. Founder at Zingrevenue. Insurance, coding and AI geek.
1yIf you're wondering about the dog and the hard hat, it's a (somewhat) mirror of the Buildah build (container compilation) CLI tool 🐶 https://buildah.io/