Skip to main content
๐Ÿ“ฌ Get weekly Production AI insights Practical notes on Kubernetes, AI infrastructure and platform engineering. No spam. Subscribe free
How to Install Ansible on Docker Container
Automation

How to Install Ansible on Docker Container

Step-by-step guide to install Ansible on Docker Container. Covers package installation, pip install, version management, and first playbook setup.

LB
Luca Berton
ยท 1 min read

Here is how to run Ansible inside a Docker container in 2026.

Quick Start

docker run --rm -v $(pwd):/ansible -w /ansible willhallonline/ansible:latest ansible-playbook playbook.yml -i inventory

Custom Dockerfile

FROM python:3.12-slim
RUN pip install --no-cache-dir ansible boto3 pywinrm && \
    ansible-galaxy collection install community.general community.docker
WORKDIR /ansible
ENTRYPOINT ["ansible-playbook"]

Build and Run

docker build -t ansible-runner .
docker run --rm -v $(pwd):/ansible -v ~/.ssh:/root/.ssh:ro ansible-runner playbook.yml -i inventory

Docker Compose

services:
  ansible:
    build: .
    volumes:
      - .:/ansible
      - ~/.ssh:/root/.ssh:ro
    environment:
      - ANSIBLE_HOST_KEY_CHECKING=False

Free 30-min Production AI consultation

Book Now