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?
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.
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.
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 .
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With