How to connect to lxd container

lxd is an easy-to-use command-line interface for lxc (Linux container). In this blog post, I will show how to create an lxd container and connect to it.

To create an lxd container, run

lxc launch ubuntu:20.04 vm-1

Here vm-1 is the name of the container. ubuntu:20.04 tells lxc to create a new container with Ubuntu version 20.04.

To see the list of containers, you can use the command

lxc ls

list lxd containers

This list IP address of the containers. If you have openssh-server installed and have a user name and password or SSH key set, you can login using the IP address.

If you just created the container, you don’t have any login, then you can use the command

lxc shell CONTAINER_NAME

connect to lxd container with lxc shell command

Another way is to use lxc exec

lxc exec CONTAINER_NAME bash

Example

root@instance-20210627-0830:~# lxc exec vm-1 bash
root@vm-1:~#

If you have a login, then you can use the command

lxc console CONTAINER_NAME

This command will give you access to the console of the container.

See lxd

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *