Impossible to map volume (host to container) /var/run/docker.sock to /var/run/docker.sock using Docker driver.
Possible root cause for molecule:
docker_container module
Possible base root cause in docker.py usage of the module
Is it possible to fix ?
Yes, but Its pretty hacky.
How ?
Map docker.sock to some other location, symbolic link the sock to /var/run/docker.sock
ansible 2.6.3
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/ilhicas/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
ansible 2.6.3
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/ilhicas/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
Molecule installation method (one of):
Ansible installation method (one of):
Driver used:
Docker
Volume /var/run/docker.sock is mapped to internal /var/run/docker.sock
using volumes
/var/run/docker.sock is missing inside container
molecule.yml
dependency:
name: galaxy
enabled: true
options:
ignore-certs: True
ignore-errors: True
#Relative path search here walks from role root folder (this case ansible) all the way to the scenario (in this case it lives under ansible/requirements.yml, for specific set ansible/molecule/scenario-name/requirements.yml)
role-file: molecule/scenario_name/requirements.yml
driver:
name: docker
lint:
name: yamllint
enabled: false
platforms:
- name: container_name
image: fiercely/centos7:systemd
privileged: True
published_ports:
- "80"
- "443"
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- /var/run/docker.sock:/var/run/docker.sock
command: "/usr/sbin/init"
groups:
- some_group
provisioner:
name: ansible
roles_path: roles
lint:
name: ansible-lint
enabled: false
inventory:
links:
group_vars: ../../group_vars/
scenario:
name: scenario_name
test_sequence:
- destroy
- dependency
- create
- prepare
- converge
- side_effect
- verify
- destroy
verifier:
name: testinfra
lint:
name: flake8
playbook.yml
- name: Converge
hosts: some_group
How to reproduce:
molecule test -s scenario_name
docker exec -it container_name bash
#Inside container
ls -laF /var/run | grep docker.sock
#Mapped docker sock is not found
I suspect the cause is that a tmpfs is mounted on /var/run (or /run if it's symlink) after /var/run/docker.sock is mounted, so the socket file is no longer visible:
$ molecule login
# mount | grep run
tmpfs on /run/docker.sock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=204704k,mode=755)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
As a work around for this issue you can
/var/run/docker.sock:/tmp/docker.sockthis will move the /tmp/docker.sock to /var/run/docker.sock where it should be :D
is there any plan to solve this issue? Currently it's a massive pain to test a playbook which uses docker_container functionality if you are developing in local.
DoD is a known issue and you should don even try to use containers to test docker related playbooks. I will close this because that is not something molecule can do anything about.
I was able to start a container insdie the molecule instance. I installed docker with Dockerfile.j2. Then I followed @wildone instructions to move the docker sockets mount inside the prepare.yml, but ran into an error. I was able to start a container with a symbolic link from inside the molecule host.
- name: Prepare
hosts: all
tasks:
- name: "link docker.sock to /var/run"
raw: ln -s /tmp/docker.sock /var/run/docker.sock