imagedockeransible

How do I tag a local docker image with ansible docker_image module?


I'm building a local docker image and I'd like to tag it, but I have no idea how the repository field should be filled for a docker image I just built locally.

Is tagging local images even possible with the docker_image module?


Solution

  • I was able to find out that the repository of the docker_image module is just the name of the image when it's locally built.

    This is how you first build the image with tag latest and then add a tag to it.

    - name: Build docker image
      become: yes
      docker_image:
        path: /tmp/foo
        name: foo
        state: present
    
    - name: Tag docker image
      become: yes
      docker_image:
        name: foo
        repository: foo
        tag: "{{ version.stdout }}"
        state: present