Bootstrap FreeKB - Ansible - Log into Docker Hub using the docker_login module
Ansible - Log into Docker Hub using the docker_login module

Updated:   |  Ansible articles

If you are not familiar with modules, check out Ansible - Getting Started with Modules.

docker_login is part of the community.docker collection. Typically, the community.docker collection is not included in the default Ansible collections. The ansible-galaxy collection install command can be used to install the community.docker collection.

ansible-galaxy collection install community.docker


The docker_login module can be used to log into Docker Hub. This is often used when you want to pull and image from a private repository, which can be done using the docker_container module. In this example, the password for Docker Hub is stored in a vault encrypted file

- hosts: all
  - name: Log into DockerHub
      username: john.doe
      password: "{{ docker_password }}"

  - name: create and start the 'foo' container from the jeremycanfield/my-image:latest image
      name: foo
      image: jeremycanfield/my-image:latest
      state: started

  - name: Log out of DockerHub
      state: absent


Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee


Add a Comment

Please enter 872a5d in the box below so that we can be sure you are a human.