Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 738
deiga Avatar asked Jul 03 '16 10:07

deiga


People also ask

How do you tag a docker image?

Docker tags are just an alias for an image ID. The tag's name must be an ASCII character string and may include lowercase and uppercase letters, digits, underscores, periods, and dashes. In addition, the tag names must not begin with a period or a dash, and they can only contain 128 characters.

How do I add tags while building docker image?

To give tag to a docker file during build command: docker build -t image_name:tag_name . otherwise it will give latest tag to you image automatically. Save this answer.

Which command is used to build and tag the docker image?

The docker build command builds Docker images from a Dockerfile and a “context”. A build's context is the set of files located in the specified PATH or URL .

When can you use the Docker_image Ansible module?

Use with state present to provide an alternate name for the Dockerfile to use when building an image. Use with state absent to un-tag and remove all images matching the specified name. Use with state present to build, load or pull an image when the image already exists.


1 Answers

Seems that there is better solution with docker_image:

tasks:
  - name: build_image
    docker_image:
      name: test_img:latest     # Name of image, may be with repo path.
      path: .
      state: present
    register: image_build

  - name: tag_version
    docker_image:
      name: test_img:latest     # Equal to name in build task.
      repository: test_img:1.2  # New tag there.
      pull: no
      state: present
    when: image_build.changed

Effect:

    $ docker images
    REPOSITORY   TAG       IMAGE ID            CREATED              SIZE
    test_img     1.2       ab14e8cce7ef        9 seconds ago        142MB
    test_img     latest    ab14e8cce7ef        9 seconds ago        142MB

Works also with pushing to repo (need to change name to full repo path).

like image 100
Paweł BB Drozd Avatar answered Oct 21 '22 04:10

Paweł BB Drozd