(howto-commands)= # How to work with MicroCloud (command cheat sheet) This guide lists the commands you need to know to do common operations in MicroCloud. This command list is not meant to be exhaustive, but it gives a general overview and serves as an entry point to working with MicroCloud. Make sure to also check the {doc}`LXD documentation `. Most commands you use in MicroCloud are actually LXD client commands and are documented in more detail in the LXD documentation. There, you can also find the {ref}`man pages ` for the {command}`lxc` command. The sections of the command list provide direct links to specific pages containing more information about the respective topics. ## Create and manage instances See {ref}`lxd:instances`. ### Check available images See {ref}`lxd:images-remote`. ```{list-table} :widths: 2 3 * - List remotes - {command}`lxc remote list` * - Switch remotes - {command}`lxc remote switch ` * - List images - {command}`lxc image list [:]` ``` ### Create instances See {ref}`lxd:instances-create` and {ref}`lxd:instances-console`. ```{list-table} :widths: 2 3 * - Create a container (without starting it) - {command}`lxc init [:] [] [flags]` * - Create and start a container - {command}`lxc launch [:] [] [flags]` * - Create a VM (without starting it) - {command}`lxc init [:] [] --vm [flags]` * - Create and start a VM and connect to its VGA console - {command}`lxc launch [:] [] --vm --console=vga [flags]` ``` ### Manage instances See {ref}`lxd:instances-manage`. ```{list-table} :widths: 2 3 * - List instances - {command}`lxc list` * - Show status information about an instance - {command}`lxc info ` * - Start an instance - {command}`lxc start [flags]` * - Stop an instance - {command}`lxc stop [flags]` * - Force-stop an instance - {command}`lxc stop --force` * - Delete an instance - {command}`lxc delete [--force|--interactive]` * - Copy an instance - {command}`lxc copy [flags]` ``` ## Access instances See {ref}`lxd:run-commands`, {ref}`lxd:instances-console`, and {ref}`instances-access-files`. ```{list-table} :widths: 2 3 * - Run a command inside an instance - {command}`lxc exec -- ` * - Get shell access to an instance (if {command}`bash` is installed) - {command}`lxc exec -- bash` * - Get console access to an instance - {command}`lxc console [flags]` * - Pull a file from an instance - {command}`lxc file pull / ` * - Push a file to an instance - {command}`lxc file pull /` ``` ## Configure instances See {ref}`lxd:instances-configure`, {ref}`lxd:profiles`, and {ref}`lxd:instance-config` (and sub-pages). ```{list-table} :widths: 2 3 * - Show the configuration of an instance - {command}`lxc config show ` * - Show the configuration of an instance, including configurations inherited from a profile - {command}`lxc config show --expanded` * - Set some configuration options for an instance (this example limits memory and CPU usage) - {command}`lxc config set limits.memory=8GiB limits.cpu=4` ```{tip} See {ref}`lxd:instance-options` for all available instance options. ``` * - Override some device options for an instance (this example sets the root disk size) - {command}`lxc config device override root size=10GiB` ```{tip} See {ref}`lxd:devices` for the device options that are available for each device type. ``` * - Edit the full configuration of an instance - {command}`lxc config edit ` * - Apply a profile to an instance - {command}`lxc profile add ` ``` ### Use `cloud-init` ```{rst-class} spellexception ``` See {ref}`lxd:cloud-init`. For example, to import an SSH key: 1. Create a profile: {command}`lxc profile create ` 1. Run {command}`lxc profile edit ` and add the following configuration to the profile: config: cloud-init.user-data: | #cloud-config ssh_authorized_keys: - 1. Launch the instance using that profile (in addition to the `default` profile): {command}`lxc launch [] --profile default --profile ` ## Manage instance snapshots See {ref}`lxd:instances-snapshots`. ```{list-table} :widths: 2 3 * - Create a snapshot - {command}`lxc snapshot [] [flags]` * - View information about a snapshot - {command}`lxc config show /` * - View all snapshots of an instance - {command}`lxc info ` * - Restore a snapshot - {command}`lxc restore [--stateful]` * - Delete a snapshot - {command}`lxc delete /` * - Create an instance from a snapshot - {command}`lxc copy / ` ``` ## Configure storage See {ref}`lxd:howto-storage-volumes`. To create a storage pool, see {ref}`lxd:howto-storage-pools`. However, keep in mind that for MicroCloud to be able to use the storage pool, it must be created for the cluster and not only for one machine. Therefore, the following example commands use the `remote` storage pool that is automatically set up in MicroCloud. ```{list-table} :widths: 2 3 * - Create a custom storage volume of content type `filesystem` in the `remote` storage pool - {command}`lxc storage volume create remote ` * - Create a custom storage volume of content type `block` in the `remote` storage pool - {command}`lxc storage volume create remote --type=block` * - Attach a custom storage volume of content type `filesystem` to an instance - {command}`lxc storage volume attach remote ` * - Attach a custom storage volume of content type `block` to an instance - {command}`lxc storage volume attach remote ` ``` ## Configure networking See {ref}`lxd:networking` (and sub-pages). ```{list-table} :widths: 2 3 * - Create a network - {command}`lxc network create --type= [options]` ```{tip} See {ref}`lxd:network-create` for detailed information. ``` * - Attach an instance to a network - {command}`lxc network attach [] []` ```{tip} See {ref}`lxd:network-attach` for detailed information. ``` * - Create and apply a network ACL to an instance - {command}`lxc network acl rule add ingress|egress [properties]` {command}`lxc network set security.acls=""` ```{tip} See {ref}`lxd:network-acls` for detailed information. ``` * - Expose an instance on an external IP - {command}`lxc network forward create target_address=` ```{tip} See {ref}`lxd:network-forwards` for detailed information. ``` ``` ## Use projects See {ref}`lxd:exp-projects` and {ref}`projects` (and sub-pages). ```{list-table} :widths: 2 3 * - Create a project - {command}`lxc project create [--config