Skip to content
Support

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.

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:

Terminal window
sudo apt install snapd
snap install lxd

Add your current user to the lxd group so that it has the correct permissions to use the application:

Terminal window
sudo usermod -aG lxd $USER

Reboot to apply the new permissions, then open a terminal again and set up LXD’s storage and network configuration with this command:

Terminal window
lxd init

Now, create your first container with this command:

Terminal window
lxc launch ubuntu:16.04 ubuntu-container

This 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:

Terminal window
lxc launch ubuntu:18.04 ubuntu-container

Or for Ubuntu 20.04:

Terminal window
lxc launch ubuntu:20.04 ubuntu-container

List and confirm that the container was created with this command:

Terminal window
lxc list

The container can be stopped with this command:

Terminal window
lxc stop ubuntu-container

Or the container can be deleted:

Terminal window
lxc delete ubuntu-container

Enter the container with this command:

Terminal window
lxc exec ubuntu-container -- /bin/bash

Or just one command can be issued without entering the container:

Terminal window
lxc exec ubuntu-container -- apt update

To push a file to the container:

Terminal window
lxc file push filename first/tmp/

To pull a file from the container:

Terminal window
lxc file pull first/tmp/filename .

For more information, refer to Ubuntu’s documenation.