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
1 |
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
1 |
lxc ls |
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
1 |
lxc shell CONTAINER_NAME |
Another way is to use lxc exec
1 |
lxc exec CONTAINER_NAME bash |
Example
1 2 |
root@instance-20210627-0830:~# lxc exec vm-1 bash root@vm-1:~# |
If you have a login, then you can use the command
1 |
lxc console CONTAINER_NAME |
This command will give you access to the console of the container.
See lxd