Docker Module in Ansible

Docker in macOS Docker in macOS

I have finally managed to install Docker CE on a freshly CentOS 8.1 installed dedicated server. Now is the time to learn Docker module in Ansible.

Why Use a Docker Module in Ansible?

Instead of using Ansible’s shell or command functionality to form/start/stop Docker containers, it’s much better to use a Docker module.

How To Install the Docker Module in Ansible

For CentOS 8.x images, here’s the Ansible playbook fragment that gets the Docker module installed on a server:

 name: Install pip3
   name: python3-pip
   state: latest
 tags: docker
 name: Install Docker module for Python (used by Ansible)
     - docker

How To Use a Docker Module in Ansible

Here’s the example from Ansible documentation:

- name: Create a simple Docker container
    name: unixtutorial-server   
    image: ubuntu   
      - /storage/ubuntu-docker
    - docker
    - containers

In this example you can see how easy it is to specify a Docker container’s name, base image (busybox in this case) and even map volumes from physical host (that /storage thing).

WARNING: this is not a complete example yet. I think more parameters need to be specified before this becomes a usable container named unixtutorial-server.

Next Steps with Docker in Ansible

I have a number of Docker images that I plan on storing using self-hosted Docker registry. They’ll be pulled and formed into clusters using Ansible.

I’m not 100% sure, but it may well be that whole Dockerfiles (read: Docker stacks) can be created and orchestrated using Ansible – we’ll see.

See Also

Keep Learning with Me

Follow me on Facebook and Twitter or jump into Telegram chat!:
I'm using Brave browser
Give it a try, it's awesome: Brave Browser
IT Consultancy
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!

Recent Tweets