Configuring Docker and WebServer in Docker container using Ansible!
In this article, we will see how we would do docker configuration using the Ansible playbook.
The task to be performed →
- First, configure the docker yum repository.
- Install Docker repository.
- Start the docker service.
- Pull the docker HTTPD image from DockerHub.
- Copy your file to the specified location of the HTTPD image to configure the webserver.
Procedure →
→ Configure Docker yum repository.
name: Setting docker yum conf
yum_repository:
name: Docker
description: desc for docker
baseurl: https://download.docker.com/linux/centos/docker-ce.repo
gpgcheck: no
- command: “yum install docker-ce — nobest -y”
→ Starting the docker service.
- service:
name: “docker”
state: started
→ Pull the HTTPD docker image from DockerHub.
- docker_image:
name: httpd
source: pull
→ Copy your file to managed node from localhost.
- copy:
src: /root/index1.html
dest: /root/index1.html
→ Launch your container, expose it, and copy your file to the webserver folder.
name: start a container
docker_container:
name: mynewOS1
image: httpd
volumes:
—
/root/index1.html:/usr/local/apache2/htdocs/index1.html/
ports:
— “82:80”
state: started
detach: yes
The aforementioned are our required problems and their solution.
The whole source code of the program could be found at the below mentioned GitHub link →
Thank you for your read!