The main intent for this project is to use this container with Molecule to test Ansible roles that deploy Docker containers.
Python 3.x and sudo as a become method are preinstalled.
latest
: Latest stable version of Docker20.10.6
: Docker Version 20.10.620.10.5
: Docker Version 20.10.519.03.15
: Docker Version 19.03.15
To use the Docker image as a platform in Molecule, add the following to the molecule/default/molecule.yml
file.
platforms:
- name: instance
image: "mreimbold/ubuntu2004-dind:latest"
command: ""
privileged: true
pre_build_image: true
To test your role in a more realistic way, a non-root user named ansible is available in the Docker image. To use this user, add the following to your molecule/default/converge.yml
file. This means that no longer all tasks are executed with root permissions and the become keyword must be set explicitly.
---
- name: Converge
...
vars:
ansible_user: ansible
- Install Docker.
- Pull this image from Docker Hub:
docker pull mreimbold/ubuntu2004-dind:latest
. - Run a container from the image:
docker run --detach --privileged --name docker mreimbold/ubuntu2004-dind:latest
- Use Docker inside the container:
docker exec --tty docker docker --help