<commit_before># Introduction

The "lxc" command is the main tool used by users to interact with LXD when
running it outside of OpenStack. The command is available to all users and can
be used to manage any local or remote resources provided they have the
credentials to do so.

# Remote operations

The lxc command line tool is designed to manage LXD hosts as well as connect
to a variety of remote resources.

The list of remote servers and their credentials is only stored in the client,
the servers don't know about each other nor do they have to. The client is the
one initiating any cross-server communication by instructing the two servers to
start talking to each other. Should that fail, for example because of a
firewall between the two servers, the client will then act as a relay
forwarding the data stream between the two servers.

* * *

# Resources
The lxc command interacts with resources. Currently supported resources are:
 * containers
 * container snapshots
 * images
 * container hosts

lxc defaults to interacting with the local LXD daemon, remote operations
must be prefixed with the remote server's name followed by a colon.

Some examples with the "status" command:

Command                               | Result
:------                               | :-----
lxc info                              | Show some information on the local LXD server
lxc info dakara:                      | Same but against the remote "dakara" server
lxc info c1                           | Show information about the "c1" container
lxc images info ubuntu/trusty/amd64   | Show information about the "ubuntu/trusty/amd64" image (alias)
lxc info dakara:c2/yesterday          | Show information about the "yesterday" snapshot of container "c2" on remote host "dakara"


This URI scheme is designed to be very specific (no ambiguity) and as short as
possible.

* * *

# Commands
## Overview

Command     | Description
:------     | :----------
config      | Change container settings (quotas, notes, OS metadata, ...)
copy        | Copy an existing container or container snapshot as a new container
delete      | Delete a resource (container, snapshot, image, ...)
exec        | Spawn a command within the container
file        | Transfer files in and out of the container
image       | Image handling
info        | Show information about a container, container snapshot or remote server
init        | Create a container without starting it
launch      | Create and start a new container from an image
list        | List all the containers
move        | Move a container either to rename it or to migrate it
profile     | Manage container configuration profiles.
publish     | Make an image out of an existing container or container snapshot
remote      | Remote server handling
restart     | Restart a container
restore     | Restore a snapshot of a container
snapshot    | Make a snapshot (stateful or not) of a container
start       | Start a container
stop        | Stop a container

* * *

## config

**Arguments**

    edit [resource]
    get [resource] <key>
    set [resource] <key> <value>
    show [resource]
    unset [resource] <key>
    device add <resource> <device name> <type> [key=value]...
    device remove <resource> <device name>
    device list <resource>
    device show <resource>
    trust add [remote] <certificate>
    trust remove [remote] <fingerprint>
    trust list [remote]

**Description**

Probably one of the most complex commands, it allows querying and
setting all the configuration options available for containers and LXD hosts.

The trust sub-command is there to manage the server's trust store. It
can list the certificates which the server currently trusts, delete
entries (based on their fingerprint) and add new entries using a
provided certificate.

The edit commands are there to offer a more convenient user interface by
opening a text editor in which the current configuration is displayed
alongside a set of useful examples. The user can then edit things in
place and when saved, all changes will be committed.

**Examples**

Command                                                                         | Result
:------                                                                         | :-----
lxc config show                                                                 | Show the local server's configuration
lxc config show dakara:                                                         | Show "dakara"'s server' configuration
lxc config set core.trust\_password <PASSWORD>                          | Set the local server's trust password to "<PASSWORD>"
lxc config set c1 limits.memory 2G                                              | Set a memory limit of 2GB for container "c1"
lxc config show c1                                                              | Show the configuration of the "c1" container, starting by the list of profiles it’s based on, then the container specific settings and finally the resulting overall configuration.
lxc config trust add new-client-cert.crt                                        | Add new-client-cert.pem to the default remote's trust store (typically local LXD)
lxc config trust add dakara: new-client-cert.crt                                | Add new-client-cert.pem to the "dakara"'s trust store
lxc config trust list                                                           | List all the trusted certificates on the default remote
lxc config trust list dakara:                                                   | List all the trusted certificates on "dakara"
lxc config trust remove [name|\<cert fingerprint\>]                             | Remove a certificate from the default remote
lxc config trust remove dakara: \<cert fingerprint\>                            | Remove a certificate from "dakara"'s trust store

* * *

## copy

**Arguments**

    <source container/snapshot> [container name]

**Description**

Creates a copy of an existing container or container snapshot as a new
container. If the new container's name isn't specified, a random one
will be generated.

**Examples**

Command                                 | Result
:------                                 | :-----
lxc copy c1 c2                          | Create a container called "c2" which is a copy of container "c1" with its hostname changed and a fresh MAC address
lxc copy c1 dakara:                     | Copy container "c1" to remote host "dakara" still keeping the name "c1" on the target
lxc copy c1 dakara:c2                   | Same as above but also rename the container and change its hostname


* * *

## delete

**Arguments**

    <container or snapshot name>

**Description**
Destroy a container or container snapshot and any attached data
(configuration, snapshots, ...).

This will destroy the resource (container) even if it is currently in use.

**Examples**

Command                         | Result
:------                         | :-----
lxc delete c1                   | Remove the c1 container, its configuration and any snapshot it may have
lxc delete c1/yesterday         | Remove the "yesterday" snapshot of "c1"
lxc delete dakara:c2/yesterday  | Remove the "yesterday" snapshot for "c2" on remote host "dakara"

* * *

## exec

**Arguments**

    <container> command...

**Description**

Execute a command inside the remote container.

**Examples**

Command                                                 | Result
:------                                                 | :-----
lxc exec c1 -- /bin/bash                                   | Spawn /bin/bash in local container c1
tar xcf - /opt/myapp \| lxc exec dakara:c2 -- tar xvf -    | Make a tarball of /opt/myapp with the stream going out to stdout, then have that piped into lxc exec connecting to a receiving tar command in container running on remote host "dakara"

* * *

## file

**Arguments**

    file push [--uid=UID] [--gid=GID] [--mode=MODE] <source> [<source>...] <target>
    file pull <source> [<source>...] <target>

**Description**
Copies file to or from the container. Supports rewriting the uid/gid/mode.

**Examples**

Command                                                 | Result
:------                                                 | :-----
lxc file push --uid=0 --gid=0 test.sh dakara:c2/root/   | Push test.sh as /root/test.sh inside container "c2" on host "dakara", rewrite the uid/gid to 0/0
lxc file pull dakara:c2/etc/hosts /tmp/                 | Grab /etc/hosts from container "c2" on "dakara" and write it as /tmp/hosts on the client

* * *<commit_msg>Fixed typo in tar command<commit_after># Introduction

The "lxc" command is the main tool used by users to interact with LXD when
running it outside of OpenStack. The command is available to all users and can
be used to manage any local or remote resources provided they have the
credentials to do so.

# Remote operations

The lxc command line tool is designed to manage LXD hosts as well as connect
to a variety of remote resources.

The list of remote servers and their credentials is only stored in the client,
the servers don't know about each other nor do they have to. The client is the
one initiating any cross-server communication by instructing the two servers to
start talking to each other. Should that fail, for example because of a
firewall between the two servers, the client will then act as a relay
forwarding the data stream between the two servers.

* * *

# Resources
The lxc command interacts with resources. Currently supported resources are:
 * containers
 * container snapshots
 * images
 * container hosts

lxc defaults to interacting with the local LXD daemon, remote operations
must be prefixed with the remote server's name followed by a colon.

Some examples with the "status" command:

Command                               | Result
:------                               | :-----
lxc info                              | Show some information on the local LXD server
lxc info dakara:                      | Same but against the remote "dakara" server
lxc info c1                           | Show information about the "c1" container
lxc images info ubuntu/trusty/amd64   | Show information about the "ubuntu/trusty/amd64" image (alias)
lxc info dakara:c2/yesterday          | Show information about the "yesterday" snapshot of container "c2" on remote host "dakara"


This URI scheme is designed to be very specific (no ambiguity) and as short as
possible.

* * *

# Commands
## Overview

Command     | Description
:------     | :----------
config      | Change container settings (quotas, notes, OS metadata, ...)
copy        | Copy an existing container or container snapshot as a new container
delete      | Delete a resource (container, snapshot, image, ...)
exec        | Spawn a command within the container
file        | Transfer files in and out of the container
image       | Image handling
info        | Show information about a container, container snapshot or remote server
init        | Create a container without starting it
launch      | Create and start a new container from an image
list        | List all the containers
move        | Move a container either to rename it or to migrate it
profile     | Manage container configuration profiles.
publish     | Make an image out of an existing container or container snapshot
remote      | Remote server handling
restart     | Restart a container
restore     | Restore a snapshot of a container
snapshot    | Make a snapshot (stateful or not) of a container
start       | Start a container
stop        | Stop a container

* * *

## config

**Arguments**

    edit [resource]
    get [resource] <key>
    set [resource] <key> <value>
    show [resource]
    unset [resource] <key>
    device add <resource> <device name> <type> [key=value]...
    device remove <resource> <device name>
    device list <resource>
    device show <resource>
    trust add [remote] <certificate>
    trust remove [remote] <fingerprint>
    trust list [remote]

**Description**

Probably one of the most complex commands, it allows querying and
setting all the configuration options available for containers and LXD hosts.

The trust sub-command is there to manage the server's trust store. It
can list the certificates which the server currently trusts, delete
entries (based on their fingerprint) and add new entries using a
provided certificate.

The edit commands are there to offer a more convenient user interface by
opening a text editor in which the current configuration is displayed
alongside a set of useful examples. The user can then edit things in
place and when saved, all changes will be committed.

**Examples**

Command                                                                         | Result
:------                                                                         | :-----
lxc config show                                                                 | Show the local server's configuration
lxc config show dakara:                                                         | Show "dakara"'s server' configuration
lxc config set core.trust\_password <PASSWORD>                          | Set the local server's trust password to "<PASSWORD>"
lxc config set c1 limits.memory 2G                                              | Set a memory limit of 2GB for container "c1"
lxc config show c1                                                              | Show the configuration of the "c1" container, starting by the list of profiles it’s based on, then the container specific settings and finally the resulting overall configuration.
lxc config trust add new-client-cert.crt                                        | Add new-client-cert.pem to the default remote's trust store (typically local LXD)
lxc config trust add dakara: new-client-cert.crt                                | Add new-client-cert.pem to the "dakara"'s trust store
lxc config trust list                                                           | List all the trusted certificates on the default remote
lxc config trust list dakara:                                                   | List all the trusted certificates on "dakara"
lxc config trust remove [name|\<cert fingerprint\>]                             | Remove a certificate from the default remote
lxc config trust remove dakara: \<cert fingerprint\>                            | Remove a certificate from "dakara"'s trust store

* * *

## copy

**Arguments**

    <source container/snapshot> [container name]

**Description**

Creates a copy of an existing container or container snapshot as a new
container. If the new container's name isn't specified, a random one
will be generated.

**Examples**

Command                                 | Result
:------                                 | :-----
lxc copy c1 c2                          | Create a container called "c2" which is a copy of container "c1" with its hostname changed and a fresh MAC address
lxc copy c1 dakara:                     | Copy container "c1" to remote host "dakara" still keeping the name "c1" on the target
lxc copy c1 dakara:c2                   | Same as above but also rename the container and change its hostname


* * *

## delete

**Arguments**

    <container or snapshot name>

**Description**
Destroy a container or container snapshot and any attached data
(configuration, snapshots, ...).

This will destroy the resource (container) even if it is currently in use.

**Examples**

Command                         | Result
:------                         | :-----
lxc delete c1                   | Remove the c1 container, its configuration and any snapshot it may have
lxc delete c1/yesterday         | Remove the "yesterday" snapshot of "c1"
lxc delete dakara:c2/yesterday  | Remove the "yesterday" snapshot for "c2" on remote host "dakara"

* * *

## exec

**Arguments**

    <container> command...

**Description**

Execute a command inside the remote container.

**Examples**

Command                                                 | Result
:------                                                 | :-----
lxc exec c1 -- /bin/bash                                   | Spawn /bin/bash in local container c1
tar cf - /opt/myapp \| lxc exec dakara:c2 -- tar xvf -    | Make a tarball of /opt/myapp with the stream going out to stdout, then have that piped into lxc exec connecting to a receiving tar command in container running on remote host "dakara"

* * *

## file

**Arguments**

    file push [--uid=UID] [--gid=GID] [--mode=MODE] <source> [<source>...] <target>
    file pull <source> [<source>...] <target>

**Description**
Copies file to or from the container. Supports rewriting the uid/gid/mode.

**Examples**

Command                                                 | Result
:------                                                 | :-----
lxc file push --uid=0 --gid=0 test.sh dakara:c2/root/   | Push test.sh as /root/test.sh inside container "c2" on host "dakara", rewrite the uid/gid to 0/0
lxc file pull dakara:c2/etc/hosts /tmp/                 | Grab /etc/hosts from container "c2" on "dakara" and write it as /tmp/hosts on the client

* * *
{'fraction_non_alphanumeric': 0.06974167589946936, 'fraction_numerical': 0.004664995043442767, 'mean_word_length': 2.0499733238484796, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 72, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2872663', 'n_tokens_mistral': 4165, 'n_tokens_neox': 3998, 'n_words': 2054}