danscarf.com

Edit Content
Click on the Edit Content button to edit/add the content.

Using Anible to install Docker

I’ve found an easy way to deploy WordPress using Docker. However, installing Docker manually is an error-prone pain. I wanted to find an easier and more reliable/consistent way to to it.

Using Ansible and Jeff Geerling’s excellent Ansible Galaxy playbook for this worked reall.y well.

On a separate machine that I had configured to be an Ansible Control node, I ran this to install the Galaxy Docker playbook:

ansible-galaxy install geerlingguy.docker

Then, I created a simple Ansible Inventory file entry to reference the VM on which I’d ultimately install WordPress:

[wordpress-servers]
wordpress.test.local

Next, I defined a simple playbook to perform the work of installing Docker on the WordPress VM:

---
    - hosts: wordpress-servers
      become: true
    
      vars:
        docker_install_compose: true
        docker_compose_version: "1.24.1"
        docker_compose_path: /usr/local/bin/docker-compose
        docker_apt_release_channel: stable
        docker_apt_arch: amd64
        docker_apt_repository: "deb [arch={{ docker_apt_arch }}] https://download.docker.com/linux/{{ ansible_distribution|lower }} {{ ansible_distribution_release }} {{ docker_apt_release_channel }}"
        docker_apt_ignore_key_error: True
    
      roles:
        - geerlingguy.docker

Executing this playbook was extremely simple:

ansible-playbook -K -i hosts wordpress.yml

The result was that Ansible remotely installed Docker on the target host without a hitch. Pretty neat!

Once complete, I SSH’ed into the WordPress VM. For convenience, I added my account to the Docker group so that I could run Docker commands without sudo:

sudo usermod -aG docker $USER

Pages: 1 2 3 4 5 6

One Response

Leave a Reply

Your email address will not be published. Required fields are marked *