tianon / docker-qemu

Dockerization of supported QEMU releases
https://qemu.org
133 stars 34 forks source link

Build a qcow2 image with packer #19

Open marcpires opened 3 years ago

marcpires commented 3 years ago

I am trying to use packer to build an image using packer. I created a custom image adding packer and other tools I need, but when I run virt-install inside the container I got the following error.

qemu-container | [Tue, 09 Mar 2021 11:44:34 virt-install 261] ERROR (cli:254) Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
qemu-container | [Tue, 09 Mar 2021 11:44:34 virt-install 261] DEBUG (cli:256) 
qemu-container | Traceback (most recent call last):
qemu-container |   File "/usr/share/virt-manager/virt-install", line 955, in <module>
qemu-container |     sys.exit(main())
qemu-container |   File "/usr/share/virt-manager/virt-install", line 937, in main
qemu-container |     conn = cli.getConnection(options.connect)
qemu-container |   File "/usr/share/virt-manager/virtinst/cli.py", line 216, in getConnection
qemu-container |     conn.open(_openauth_cb, None)
qemu-container |   File "/usr/share/virt-manager/virtinst/connection.py", line 138, in open
qemu-container |     open_flags)
qemu-container |   File "/usr/lib/python3/dist-packages/libvirt.py", line 104, in openAuth
qemu-container |     if ret is None:raise libvirtError('virConnectOpenAuth() failed')
qemu-container | libvirt.libvirtError: **Failed to connect socket to '/var/run/libvirt/libvirt-sock'**: No such file or directory
qemu-container | make: *** [Makefile:100: virt-install] Error 1

Adding a volume to my '/var/run/libvirt/libvirt-sock' it works, but as I plan to use this in a CI, it would require my agent to have QEMU/KVM installed.

tianon commented 3 years ago

Sorry, I don't know how I missed this earlier!

This sounds like you're not running libvirt inside your container, which is likely going to be necessary to use libvirt there. :sweat_smile:

I'm really very unfamiliar with Packer though -- does it maybe have a direct QEMU harness instead of going through libvirt?

MaxPeal commented 2 years ago

@marcpires have you a link to youre packer.json / packer.pkr.hcl?

@tianon yes packer use QEMU directly but also hase many other plugins that can work / or can not work. https://www.packer.io/plugins/builders/qemu