Containers on Linux
Sometimes, an older version of a library or libraries for an application is needed for development. It is faster and easier to use LXC/LXD to set up a container of that release and work in that container.
Software
Section titled “Software”First, open a terminal using the keyboard shortcut for your operating system:
Pop!_OS : SUPER + T
Ubuntu : CTRL+ALT+T
Install the software by running these commands in the terminal:
sudo apt install snapdsnap install lxdAdd your current user to the lxd group so that it has the correct permissions to use the application:
sudo usermod -aG lxd $USERReboot to apply the new permissions, then open a terminal again and set up LXD’s storage and network configuration with this command:
lxd initCreate a container
Section titled “Create a container”Now, create your first container with this command:
lxc launch ubuntu:16.04 ubuntu-containerThis will create a container based on Ubuntu 16.04 with the name ‘ubuntu-container’. You can change the version depending on the OS version that you need. For example, for Ubuntu 18.04:
lxc launch ubuntu:18.04 ubuntu-containerOr for Ubuntu 20.04:
lxc launch ubuntu:20.04 ubuntu-containerList and confirm that the container was created with this command:
lxc listThe container can be stopped with this command:
lxc stop ubuntu-containerOr the container can be deleted:
lxc delete ubuntu-containerEnter the container
Section titled “Enter the container”Enter the container with this command:
lxc exec ubuntu-container -- /bin/bashOr just one command can be issued without entering the container:
lxc exec ubuntu-container -- apt updateSharing files
Section titled “Sharing files”To push a file to the container:
lxc file push filename first/tmp/To pull a file from the container:
lxc file pull first/tmp/filename .For more information, refer to Ubuntu’s documenation.