lxclxd

What is the difference between lxc commands lxc start and lxc-start, etc?


Its not clear from the documentation what is the difference between lxc start and lxc-start and the --help provides different usages and switches. Tutorials use both variants but delving into the documentation a bit deeper, it seems that lxc-start is suited for applications running inside the container whereas lxc start is for starting a container. Either way its not clear since it doesn't explain if the commands are links of one another or completely different. I am erring on the side of "they are different as in different binaries, different code paths, but eventually converge under the hood with a few modifications".

Documentation: http://manpages.ubuntu.com/manpages/bionic/man1/lxc-start.1.html

$ lxc-start --help
Usage: lxc-start --name=NAME -- COMMAND

lxc-start start COMMAND in specified container NAME

Options :
  -n, --name=NAME        NAME of the container
  -d, --daemon           Daemonize the container (default)
  -F, --foreground       Start with the current tty attached to /dev/console
  -p, --pidfile=FILE     Create a file with the process id
  -f, --rcfile=FILE      Load configuration file FILE
  -c, --console=FILE     Use specified FILE for the container console
  -L, --console-log=FILE Log container console output to FILE
  -C, --close-all-fds    If any fds are inherited, close them
                         If not specified, exit with failure instead
                         Note: --daemon implies --close-all-fds
  -s, --define KEY=VAL   Assign VAL to configuration variable KEY
      --share-[net|ipc|uts]=NAME Share a namespace with another container or pid

Common options :
  -o, --logfile=FILE               Output log to FILE instead of stderr
  -l, --logpriority=LEVEL          Set log priority to LEVEL
  -q, --quiet                      Don't produce any output
  -P, --lxcpath=PATH               Use specified container path
  -?, --help                       Give this help list
      --usage                      Give a short usage message
      --version                    Print the version number

Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.

See the lxc-start man page for further information.

Documentation: http://manpages.ubuntu.com/manpages/bionic/man7/lxc.7.html

$ lxc start --help
Usage: lxc start [<remote>:]<container> [[<remote>:]<container>...]

Start containers.

Options:
    --debug  (= false)
        Enable debug mode
    --force-local  (= false)
        Force using the local unix socket
    --no-alias  (= false)
        Ignore aliases when determining what command to run
    --stateful  (= false)
        Store the container state (only for stop)
    --stateless  (= false)
        Ignore the container state (only for start)
    --verbose  (= false)
        Enable verbose mode

Solution

  • From https://discuss.linuxcontainers.org/t/comparing-lxd-vs-lxc/24,

    It states,

    lxd

    lxd is the LXD daemon. For interacting with the daemon (to create and manage containers, for instance), you want to use the lxc command. You generally don’t want to invoke lxd directly – unless you need to run lxd init or something; check man lxd or lxd --help for more info on what you can do with running lxd directly, but once you get it running from your init system, you probably won’t need to invoke it directly again unless you are debugging LXD itself.

    The lxc command is the LXD front-end (“LXD Client” is how I think of it).

    However, if you’re trying to use LXD, you should avoid using any commands that start with lxc- (that’s lxc, followed by a short hyphen)! These commands are associated with LXC.

    lxc

    LXC commands start with lxc- (that’s lxc followed by a short hyphen). If there’s no hyphen, just the literal command lxc, that’s associated with LXD.