Copy all directories, files, and rpm packages required to execute ansible to the docker container side. To run ansible locally inside the container.
Install python and pip.
Install the required roles from ansible-galaxy. (community.general, community.crypto)
Unset the start of some services (chrony, http, mackerel, sshd). This is because docker has the concept of one container and one service, and it is premised on controlling by starting and stopping the container itself, not controlling the service in the container, and it is not possible to control the start and stop of services.
Open the required port in Dockerfile (EXPOSE 80 443) and specify it when starting the container with docker run.
Dockerfile
FROM centos:centos8
RUN dnf clean all && rm -r /var/cache/dnf && dnf upgrade -y && dnf update -y
RUN dnf install -y sudo
RUN dnf install -y python3-pip
RUN pip3 install ansible
RUN ansible-galaxy collection install community.crypto
RUN ansible-galaxy collection install community.general
COPY ./ ./.
RUN ansible-playbook dev.yml
EXPOSE 80 443
CMD ["/bin/bash"]
~~~
Example of execution when creating an image and starting a container
$ cd (directory with Dockerfile) $ docker build -t web/dev:1.0 .
$ docker run -itd -p 80:80 -p 443:443 --name test web/dev:1.0
~~~
that's all.
Recommended Posts