Most people build containers using a Dockerfile
, but it's easy (and sometimes much more manageable) to build containers other ways.
In this example, Ansible is used to:
- Start a container.
- Run Ansible roles to install Java and Apache Solr on the container.
- Commit the container image.
- Stop and remove the container.
Effectively the same as using a Dockerfile
and docker build
, but built using Ansible's automation engine, which offers more flexibility for advanced use cases, or supporting numerous different base images and distributions—or for supporting an application build on both legacy servers and inside containers, with shared automation and configuration code.
If you want a maintained Apache Solr container to use in your infrastructure, I recommend using the
geerlingguy/solr
image, available on Docker Hub. It is built using a similar playbook, but is available to pull from anywhere, and has tags available for many Solr versions.
This playbook assumes you have Docker CE, Ansible (pip[3] install ansible
), and the Docker Python library installed (pip[3] install docker
).
In this playbook directory, install dependencies from Ansible Galaxy:
ansible-galaxy install -r requirements.yml
Run the playbook to build the Apache Solr container image:
ansible-playbook -i inventory main.yml
A test.yml
playbook is included which runs a container with the image the main.yml
built, then verifies Solr starts and runs correctly, then stops and removes the container. To run the test playbook:
ansible-playbook -i inventory test.yml