Isolate development environments with LXD containers

I will talk about the approach to organizing local isolated development environments on my workstation. The approach was developed under the influence of the following factors:


  • different languages ​​need different IDEs and toolchains;
  • Different projects may use different versions of toolchains and libraries.

The approach is to develop containers inside LXD running locally on a laptop or workstation with redirecting graphics output to the host.


Configuration on the example of Ubuntu 20.04 .


Reflections on options and reasons are given at the end of the article.


1. Install LXD


On Ubuntu 20.04, LXD is no longer available for installation as a deb package, only through snap:


$ snap install lxd

After installation, you need to perform initialization:


$ lxd init

The only parameter that I change is that storage bakendI use diras the simplest. Since I do not use snapshots and copies, the warnings in the documentation do not scare me:


Similarly, the directory backend is to be considered as a last resort option.
It does support all main LXD features, but is terribly slow and inefficient as it can't perform
instant copies or snapshots and so needs to copy the entirety of the instance's storage every time.

2. LXD profile setup


LXD β€” . default :


  • $ lxc profile device add default X0 disk source=/tmp/.X11-unix/X0 path=/tmp/.X11-unix/X0 β€” X11 ;
  • $ lxc profile set default environment.DISPLAY :0 β€” DISPLAY ;
  • $ lxc profile set default raw.idmap "both 1000 1000" β€” .

3.


images:ubuntu/20.04:


$ lxc launch images:ubuntu/20.04 dev1

https://images.linuxcontainers.org, . images: . Ubuntu : $ lxc launch ubuntu/20.04 dev1.


:


$ lxc exec dev1 -- bash

Firefox VS Code ( ):


$ apt update
$ apt install curl gpg firefox

$ curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
$ install -o root -g root -m 644 packages.microsoft.gpg /usr/share/keyrings/
$ echo "deb [arch=amd64 signed-by=/usr/share/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list

$ apt update
$ apt install code


poweroff

! GPU , . :


  • $ lxc config device add dev1 mygpu gpu;
  • β€” , .

4.


, , :


lxc start dev1

VS Code ubuntu:


lxc exec dev1 -- sudo --login --user ubuntu code

Firefox:


lxc exec dev1 -- sudo --login --user ubuntu firefox

, β€” ssh.


, β€” .


5.


, , , . , , , . OpenSSL , .


:


  • (KVM, VirtualBox ..) β€” , , Windows ( , Linux) ;
  • (Cloud9 , Eclipse Che ..) β€” , , β€” ;
  • Docker β€” , , .

. : , (Puppet, Ansible ..), Docker. LXD , β€” $ lxc launch images:ubuntu/16.04 dev16.


, β€” , . .




All Articles