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 inventoryCustom 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 inventoryDocker Compose
services:
ansible:
build: .
volumes:
- .:/ansible
- ~/.ssh:/root/.ssh:ro
environment:
- ANSIBLE_HOST_KEY_CHECKING=False

