LXD client inside docker

Is it possible to run the LXD client inside docker container? I tried to use the ubuntu:focal container and install the lxd-client package in it, but when I try to run it I get information that lxd installation from snap is required.

root@1949b136e5a2:/# apt-get install lxd-client -y
root@1949b136e5a2:/# lxc ls

Command '/usr/bin/lxc' requires the lxd snap to be installed.
Please install it with:

snap install lxd

root@1949b136e5a2:/# snap install lxd
error: cannot communicate with server: Post http://localhost/v2/snaps/lxd: dial unix /run/snapd.socket: connect: no such file or directory

Is there any way to run the LXD client from docker? I need that for my pipeline.

Hi @Michal_Kzn,
AFAIK you cant, docker system do not support systemd and to install lxd easily you need snapd package which depends other system level packages. You can check that page for more detail, https://ubuntu.com/blog/lxd-vs-docker

On windows and macos it is possible to compile only the lxd client (LXD client on Windows and macOS | Ubuntu). This is not possible in a docker container?

Humm, I see, Which linux distribution are you using?

I’m trying to compile that in ubuntu focal container but without success.

root@b0f5e1ca6b57:~# go version
go version go1.16.4 linux/amd64

root@b0f5e1ca6b57:~# go get github.com/lxc/lxd/lxc
go: downloading github.com/lxc/lxd v0.0.0-20221108154730-7f005c1f120d
go: downloading github.com/gorilla/websocket v1.5.0
go: downloading github.com/mattn/go-colorable v0.1.13
go: downloading github.com/sirupsen/logrus v1.9.0
go: downloading github.com/spf13/cobra v1.6.0
go: downloading golang.org/x/crypto v0.1.0
go: downloading golang.org/x/sys v0.1.0
go: downloading golang.org/x/term v0.1.0
go: downloading gopkg.in/yaml.v2 v2.4.0
go: downloading github.com/juju/persistent-cookiejar v1.0.0
go: downloading gopkg.in/juju/environschema.v1 v1.0.1
go: downloading gopkg.in/macaroon-bakery.v3 v3.0.0
go: downloading github.com/fvbommel/sortorder v1.0.2
go: downloading github.com/olekukonko/tablewriter v0.0.5
go: downloading github.com/flosch/pongo2 v0.0.0-20200913210552-0d938eb266f3
go: downloading github.com/pkg/xattr v0.4.9
go: downloading github.com/gosexy/gettext v0.0.0-20160830220431-74466a0a0c4a
go: downloading golang.org/x/text v0.4.0
go: downloading github.com/pkg/sftp v1.13.5
go: downloading github.com/mattn/go-isatty v0.0.16
go: downloading github.com/cpuguy83/go-md2man v1.0.10
go: downloading github.com/cpuguy83/go-md2man/v2 v2.0.2
go: downloading github.com/spf13/pflag v1.0.5
go: downloading gopkg.in/yaml.v3 v3.0.1
go: downloading github.com/inconshreveable/mousetrap v1.0.1
go: downloading github.com/juju/go4 v0.0.0-20160222163258-40d72ab9641a
go: downloading golang.org/x/net v0.1.0
go: downloading gopkg.in/errgo.v1 v1.0.1
go: downloading gopkg.in/retry.v1 v1.0.3
go: downloading github.com/juju/schema v1.0.1
go: downloading gopkg.in/httprequest.v1 v1.2.1
go: downloading github.com/juju/webbrowser v1.0.0
go: downloading github.com/julienschmidt/httprouter v1.3.0
go: downloading gopkg.in/macaroon.v2 v2.1.0
go: downloading github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
go: downloading github.com/pborman/uuid v1.2.1
go: downloading github.com/robfig/cron/v3 v3.0.1
go: downloading github.com/mattn/go-runewidth v0.0.14
go: downloading github.com/kr/fs v0.1.0
go: downloading github.com/go-macaroon-bakery/macaroonpb v1.0.0
go: downloading github.com/rogpeppe/fastuuid v1.2.0
go: downloading github.com/russross/blackfriday v1.5.2
go: downloading github.com/google/uuid v1.3.0
go: downloading github.com/rivo/uniseg v0.4.2
go: downloading github.com/russross/blackfriday/v2 v2.1.0
go: downloading github.com/golang/protobuf v1.5.2
go: downloading google.golang.org/protobuf v1.28.1
//go:build comment without // +build comment
go/pkg/mod/github.com/lxc/lxd@v0.0.0-20221108154730-7f005c1f120d/client/connection.go:17:2: //go:build comment without // +build comment
go/pkg/mod/github.com/lxc/lxd@v0.0.0-20221108154730-7f005c1f120d/lxc/utils/cancel.go:10:2: //go:build comment without // +build comment
go/pkg/mod/github.com/lxc/lxd@v0.0.0-20221108154730-7f005c1f120d/shared/network.go:19:2: //go:build comment without // +build comment
go/pkg/mod/github.com/lxc/lxd@v0.0.0-20221108154730-7f005c1f120d/shared/validate/validate.go:21:2: //go:build comment without // +build comment
go/pkg/mod/github.com/lxc/lxd@v0.0.0-20221108154730-7f005c1f120d/client/lxd.go:22:2: //go:build comment without // +build comment
go/pkg/mod/github.com/lxc/lxd@v0.0.0-20221108154730-7f005c1f120d/shared/logger/log.go:10:2: //go:build comment without // +build comment
go/pkg/mod/github.com/lxc/lxd@v0.0.0-20221108154730-7f005c1f120d/lxc/main.go:18:2: //go:build comment without // +build comment
go/pkg/mod/github.com/mattn/go-runewidth@v0.0.14/runewidth.go:7:2: //go:build comment without // +build comment
root@b0f5e1ca6b57:~# $?
bash: 1: command not found

After upgrade golang to latest version the build was successful :smiling_face_with_three_hearts:

go install github.com/lxc/lxd/lxc@latest

root@b0f5e1ca6b57:~# go/bin/lxc version
Client version: 5.7

Thanks for your help :slight_smile:

Marvelous, you are welcome. :smiling_face:
AFAIK, you need at least 1.18.X for golang.

1 Like