In my last post I have configured on prem HTTP server, but it is easier to just containerise app and http servers, because this way one doesn’t need to worry about dependencies installed on host server. Instead, everything required for instance to start properly is shipped together with a container and stored/versioned in repository.
In my repository I have created “files” folder in which all necessery artifacts like app builds, HTML webpages or Dockerfiles are going to be stored and used in Ansible playbooks as needed. So far the contents look as following:
The target is to deliver only what is needed for given container.
For purpose of this exercise I have created a Dockerfile which will be used to prepare Docker image of the server. Having an image allows possibility to create multiple instances of container in reliable and repeatable way. Below is content of the Dockerfile:
It is very simple example, in which I use official DockerHub image of Httpd and modify it slightly to my needs – copying HTML static content and exposing port 80 on container, to be more precise.
We’ve got everything needed to build the container, let’s automate this action in a playbook. Below you can find how does it look like:
In first few steps I create and configure a destination directory in which related dependency files are going to be placed and copy them to specified target. Afterwards an image called “httpd” is built from provided dockerfile utilizing Docker build command. In the very last step an instance of the container is created, named http01, mapping port 80 on container to port 8080 on host machine.
After running the playbook you should receive following output:
One last thing to check is wether deployed static content can be reached on target host. This time instead of using browser let’s try to use Curl utility and fetch the content of webpage. To do this run following command on application server(app01):
As you can see the content is available, like it should be:
That’s it for today’s entry. In my next post I will be creating an application server in Docker with a .war application deployed by Ansible.