Environment
RHEL, CentOS
Description
Process to build docker image from ansible playbook. This involves creating a base image with ansible installed. With this we add the ansible repo and then configure the host with ansible playbook and tag it.
Dockerfile
FROM centos:7 AS centos7_ansible28
# Add playbooks to the Docker image
RUN yum group install "Development Tools" -y
RUN yum install epel-release -y
RUN yum install python2 python-devel python-setuptools python2-pip -y
RUN pip install ansible == 2.8
RUN ansible --version
RUN mkdir /etc/ansible
WORKDIR /etc/ansible
FROM centos7_ansible28 AS nginx
# Add the ansible repo
ADD ansible /etc/ansible/
# run ansible to configure this image
RUN ansible-playbook playbooks/nginx.yml -i /etc/ansible/inventory -c local
EXPOSE 80 443
Using above file and a valid nginx.yml playbook execute the build.
docker build .
## For systemd red this blog post running-systemd-within-docker-container