community.docker.docker_image – Manage docker images
This plugin is part of the community.docker collection (version 2.0.2).
You might already have this collection installed if you are using the
It is not included in
To check whether it is installed, run
ansible-galaxy collection list.
To install it, use:
ansible-galaxy collection install community.docker.
To use it in a playbook, specify:
Build, load or pull an image, making the image available for creating containers. Also supports tagging an image, pushing an image, and archiving an image to a
The below requirements are needed on the host that executes this module.
Docker API >= 1.20
Docker SDK for Python: Please note that the docker-py Python module has been superseded by docker (see here for details). For Python 2.6,
docker-pymust be used. Otherwise, it is recommended to install the
dockerPython module. Note that both modules should not be installed at the same time. Also note that when both modules are installed and one of them is uninstalled, the other might no longer function and a reinstall of it is required.
Connect to the Docker daemon by providing parameters with each task or by defining environment variables. You can define
DOCKER_TIMEOUT. If you are using docker machine, run the script shipped with the product that sets up the environment. It will set these variables for you. See https://docs.docker.com/machine/reference/env/ for more details.
When connecting to Docker daemon with TLS, you might need to install additional Python packages. For the Docker SDK for Python, version 2.4 or newer, this can be done by installing
Note that the Docker SDK for Python only allows to specify the path to the Docker configuration for very few functions. In general, it will use
DOCKER_CONFIGenvironment variable is not specified, and use
This module uses the Docker SDK for Python to communicate with the Docker daemon.
- name: Pull an image community.docker.docker_image: name: pacur/centos-7 source: pull # Select platform for pulling. If not specified, will pull whatever docker prefers. pull: platform: amd64 - name: Tag and push to docker hub community.docker.docker_image: name: pacur/centos-7:56 repository: dcoppenhagan/myimage:7.56 push: yes source: local - name: Tag and push to local registry community.docker.docker_image: # Image will be centos:7 name: centos # Will be pushed to localhost:5000/centos:7 repository: localhost:5000/centos tag: 7 push: yes source: local - name: Add tag latest to image community.docker.docker_image: name: myimage:7.1.2 repository: myimage:latest # As 'latest' usually already is present, we need to enable overwriting of existing tags: force_tag: yes source: local - name: Remove image community.docker.docker_image: state: absent name: registry.ansible.com/chouseknecht/sinatra tag: v1 - name: Build an image and push it to a private repo community.docker.docker_image: build: path: ./sinatra name: registry.ansible.com/chouseknecht/sinatra tag: v1 push: yes source: build - name: Archive image community.docker.docker_image: name: registry.ansible.com/chouseknecht/sinatra tag: v1 archive_path: my_sinatra.tar source: local - name: Load image from archive and push to a private registry community.docker.docker_image: name: localhost:5000/myimages/sinatra tag: v1 push: yes load_path: my_sinatra.tar source: load - name: Build image and with build args community.docker.docker_image: name: myimage build: path: /path/to/build/dir args: log_volume: /var/log/myapp listen_port: 8080 source: build - name: Build image using cache source community.docker.docker_image: name: myimage:latest build: path: /path/to/build/dir # Use as cache source for building myimage cache_from: - nginx:latest - alpine:3.8 source: build
Common return values are documented here, the following are the fields unique to this module:
Image inspection results for the affected image.
added in 1.0.0 of community.docker
Docker build output when building an image.