Should you use Ansible to build container images?
IntermediateProductionArchitecture Decisions and Tool Comparisons
Answer
Usually not. A Dockerfile or Containerfile gives layer caching, reproducible builds and tooling everyone understands. Running a playbook inside an image build produces big, uncached layers, needs Python in the image and hides what is installed.
Where Ansible does fit around containers:
- Installing and configuring Docker, Podman or containerd on hosts.
- Deploying and updating containers on plain VMs with
community.docker.docker_containerorcontainers.podman.podman_container, or with Quadlet units. - Building images through
community.docker.docker_imageas part of a larger workflow, which still uses the Dockerfile.
Execution environments are the exception: ansible-builder generates a Containerfile for you, which is the right way to build those.
More on Architecture Decisions and Tool Comparisons
Ansible or Terraform: where do you draw the line?BeginnerHow does Ansible compare with Puppet, Chef and Salt?IntermediateWhy use Ansible instead of shell scripts?BeginnerWhere does Ansible fit once you run Kubernetes?Intermediatecloud-init or Ansible for first boot configuration?IntermediateWhen would you use AWS Systems Manager instead of, or together with, Ansible?Intermediate