Closed
Description
When attaching a network to an image to be built, the task Build an Ansible compatible image (new)
is failing with this error message :
TASK [Build an Ansible compatible image (new)] *********************************
failed: [localhost] (item=molecule_local/ubuntu:focal) => {"ansible_loop_var": "item", "attempts": 3, "changed": false, "item": {"ansible_index_var": "i", "ansible_loop_var": "item", "changed": false, "checksum": "427fd5c760fa188bddada9aa5ea68e5bb0ee04bc", "dest": "/home/eric/.cache/molecule/ansible-role-teleport/default/Dockerfile_ubuntu_focal", "diff": {"after": {"path": "/home/eric/.cache/molecule/ansible-role-teleport/default/Dockerfile_ubuntu_focal"}, "before": {"path": "/home/eric/.cache/molecule/ansible-role-teleport/default/Dockerfile_ubuntu_focal"}}, "failed": false, "gid": 1000, "group": "eric", "i": 0, "invocation": {"module_args": {"_diff_peek": null, "_original_basename": "Dockerfile.j2", "access_time": null, "access_time_format": "%Y%m%d%H%M.%S", "attributes": null, "dest": "/home/eric/.cache/molecule/ansible-role-teleport/default/Dockerfile_ubuntu_focal", "follow": true, "force": false, "group": null, "mode": "0600", "modification_time": null, "modification_time_format": "%Y%m%d%H%M.%S", "owner": null, "path": "/home/eric/.cache/molecule/ansible-role-teleport/default/Dockerfile_ubuntu_focal", "recurse": false, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "state": "file", "unsafe_writes": false}}, "item": {"cgroupns_mode": "host", "command": "", "docker_networks": [{"name": "teleport-network"}], "exposed_ports": ["443/tcp"], "groups": ["all", "proxy"], "image": "ubuntu:focal", "name": "ubuntu-focal-proxy", "network_mode": "teleport-network", "pre_build_image": false, "privileged": true, "tmpfs": ["/run", "/tmp"], "volumes": ["/sys/fs/cgroup:/sys/fs/cgroup:rw", "/var/lib/containerd"]}, "mode": "0600", "owner": "eric", "path": "/home/eric/.cache/molecule/ansible-role-teleport/default/Dockerfile_ubuntu_focal", "size": 1494, "state": "file", "uid": 1000}, "msg": "Error building molecule_local/ubuntu - code: None, message: network teleport-network not found, logs: ['Step 1/6 : FROM ubuntu:focal', '', 'Pulling from library/ubuntu', 'Digest: sha256:450e066588f42ebe1551f3b1a535034b6aa46cd936fe7f2c6b0d72997ec61dbd', 'Status: Image is up to date for ubuntu:focal', ' ---> 680e5dfb52c7', 'Step 2/6 : RUN apt-get update && apt-get install -y --no-install-recommends python3 locales ca-certificates systemd systemd-sysv openssl apt-transport-https gpg-agent gnupg iproute2 sqlite3 iputils-ping inetutils-traceroute net-tools vim python3-apt && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && cd /lib/systemd/system/sysinit.target.wants/ && ls | grep -v systemd-tmpfiles-setup | xargs rm -f $1 && rm -f /lib/systemd/system/multi-user.target.wants/* && rm -f /etc/systemd/system/*.wants/* && rm -f /lib/systemd/system/local-fs.target.wants/* && rm -f /lib/systemd/system/sockets.target.wants/*udev* && rm -f /lib/systemd/system/sockets.target.wants/*initctl* && rm -f /lib/systemd/system/basic.target.wants/* && rm -f /lib/systemd/system/anaconda.target.wants/* && rm -f /lib/systemd/system/plymouth* && rm -f /lib/systemd/system/systemd-update-utmp*', '', ' ---> Running in 5450319b692a', 'Removing intermediate container 5450319b692a']"}
The main error is : message: network teleport-network not found
Maybe I'm misusing docker_networks
or network_mode
, so here the snippet I'm using (I'm creating 3 containers like this one) :
platforms:
- name: ubuntu-focal-proxy
image: ubuntu:focal
pre_build_image: false
privileged: true
command: ""
cgroupns_mode: host
tmpfs:
- /run
- /tmp
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- /var/lib/containerd
docker_networks:
- name: teleport-network
network_mode: teleport-network
exposed_ports:
- 443/tcp
groups:
- all
- proxy
If I understand the issue correctly, the step of creation of networks should be before the build. I've tested it locally and it works well. I'll send a PR for this issue.
Let me know if you need more information.