Deploying a sample application
In this recipe, we will be deploying our favorite phonebook application using Docker containers. Referring to the code files, we have created a Dockerfile and added the steps to bake our application into a Docker image. Then, we created docker-compose.yml
, in which we have added our service as a phonebook and mapped it to the port of the host container, which is 8080
.
How to do it…
Let's write a playbook for the application on how to build and run a phonebook service using ansible-playbook
:
--- - hosts: localhost roles: - phonebook
$ ansible-playbook --become phonebook.yml
How it works...
After we have run ansible-playbook
, Ansible will execute docker-compose
using the module docker_service
and will map the host port 8080
to the container's port, 8080
. Once the playbook has finished executing, we can browse localhost:8080
, and our application will be ready.