Configuring Docker and WebServer in Docker container using Ansible!

Utkarsh Srivastava
2 min readMar 15, 2021

--

In this article, we will see how we would do docker configuration using the Ansible playbook.

The task to be performed →

  1. First, configure the docker yum repository.
  2. Install Docker repository.
  3. Start the docker service.
  4. Pull the docker HTTPD image from DockerHub.
  5. 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

my output

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!

--

--