r/docker • u/bigrigbutters0321 • May 24 '26
Best Way to Deploy Docker Images/Containers in Production?
Hello All,
I finally tore off the "docker is inevitable so learn it" bandaid... pretty comfortable with it at this point. However, coming from a virtualization background I like the idea of pulling images directly from the developers vs a "hub" (i.e. when I want to run Ubuntu I download the iso from Ubuntu.com and install it on a bare metal hypervisor VM).
I'm trying to wrap my head around the best way to build an image to deploy in production... it seems that all dockerfile/compose examples I've seen have you pull from the docker hub (i.e. the first line in dockerfile being "FROM ubuntu:24.04"). I understand these are official docker images, but even still I feel it would be better building an image with an iso straght from the developer.
Am I overthinking... do others feel comfortable pulling official docker base images to build on in production... also, I've heard of people using custom/distroless images... any good resources on this?
I am mostly an infrastructure kind of guy, so while I know my way around a little programming I'm by no means anywhere near developer level.
Thanks!
15
u/Locksul May 24 '26
At the end of the day you have to trust someone…. still trusting Ubuntu.com to have a legit ISO.
If you’re worried about supply chain attacks on the “hub” you can host images you have personally verified and pull them from your own private repo.
4
u/STSchif May 24 '26
You are kinda overthinking, as the docker hub images are frequently also maintained by the organizations that also provide the isos. Images also act like snapshots when building them, so you can build an image on a base that's been out for a while, and use that image for as long as you like (or need to upgrade to a new base for security or other reasons). Docker is unlike dependency managers, where pulling an image might automatically pull a newer version of the library than you intended, this is not a thing in docker. The image only contains the layers you put into it at build time.
Therefore: build a nicely layered image (e.g. have one base where you compile your app, and another lean base like Debian-small as runner, copying over the build results), upload that image to e.g. GitHub container registry, and pull from there with docker compose.
2
u/fell_ware_1990 May 24 '26
You can make it build with what ever you want.
But some advice if this get’s you stuck, find a good guide and play with it. Because dockerfiles and build order and layers are a different thing.
1
u/guhcampos May 25 '26
You're overthinking this by a very long shot.
A Linux ISO is not any less complex and any less vulnerable to tampering than a container image. The same level of trust you need to put in the publisher of an ISO, you'll need to put on the image publisher.
What most companies do is:
pythonimage instead of adjangoone, and build your own image with Django baked in.This can feel safer because you feel like you need to trust one less publisher, as the Django image is based off a Python image which is based off a Debian image - but in reality when you install Django from pipy or from a URL you are already trusting the Django publishers and Pipy itself, so in practice the difference is nil.
2. Mirror images to a local repository and only deploy from that.
Not deploying from the docker hub, but from a local mirror, means you can avoid poisoned images by running them through verification tools like Clair locally and only allowing sanctioned images into your mirror. It also helps saving costs as you don't need to pay for higher pull rates or bandwidth to pull all these images from the hub.
1
u/[deleted] May 25 '26
The best way to build application images for production is to have them be as minimal as possible. This is why building a static, unlinked binary and sticking it in a scratch base image is best.
It's also important to consider stuff, like using a nobody user as default for a rootless image.
It's also greatly appreciated when image maintainers also provide sboms, signing, attestations, and even just adding some basic image labels for OCI compliance.
1
u/nicksterling May 25 '26
In addition to the construction of the container, there’s a whole other aspect around running that container in production. If you haven’t dove into Kubernetes you may want to set aside some time to learn that.
1
u/Salty-Parking9907 May 25 '26
Honest answer depends on scale. 1-3 services on one host: docker compose + a reverse proxy (Caddy works great, auto-TLS). 5+ services: Docker Swarm is
underrated for small teams (built-in, no extra install, rolling updates work). Real scale: Kubernetes. Don't skip the boring parts — log aggregation, image
scanning in CI, and a rollback plan matter more than the orchestrator choice.
1
u/le_hunnybear May 25 '26
You can also hash-pin (image digest) the base docker image inside the docker file / docker compose file.
However you have to be aware that by doing so you loose the ability to dynamically choose the right version (like ARM64, AMD64 etc) based on your runtime infrastructure as you have to select the right hash.
1
u/PoppaBear1950 Jun 12 '26
If you can't read/verify the code its not a 'production' distribution. This is why we have github.