# Command line reference This page is for running containers from a terminal or a script. For the same things through the app, read the [Android app guide](Usage-Android-App.md); for complete projects, see the [recipes](Cool-things-you-can-do.md). The `droidspaces` binary is the same on Linux and Android, and so are its commands and flags. On Android the app installs it at `/data/local/Droidspaces/bin/droidspaces`; the **Integrate Droidspaces to the system path** setting links it into `/system/bin` after a reboot, so a root shell finds it by name. Most commands need root, and the kernel needs namespaces and a few other features: `droidspaces check` lists what yours has. ``` droidspaces [options] [args] droidspaces [options] run [--] [args] ``` Options and the command can come in any order, short and long forms are interchangeable, and `=` is optional: `droidspaces -n web start` and `droidspaces start --name=web` are the same. The one exception is `run`: everything after it belongs to the command, so put your options before it. | Global option | Meaning | |---------------|---------| | `-n`, `--name=NAME` | The container. Can be left out of `stop`, `restart`, `enter`, `run`, `info` and `pid` when exactly one container is running. | | `-C`, `--conf`, `--config=FILE` | Load the container's config from this file. | | `--json` | JSON output from `show`, `info` and `check`. | | `--help` | Same as `help`. | | `DS_NO_PROXY=1` | An environment variable, not a flag: the binary does the work itself instead of handing it to the daemon. | ## Commands | Command | What it does | |---------|--------------| | [`start`](#start) | Boots a container. | | [`stop`](#stop) | Shuts one or more containers down. | | [`restart`](#restart) | Stops and starts a running container. | | [`enter`](#enter) | Opens a shell inside a running container. | | [`run`](#run) | Runs one command inside a running container. | | [`show`](#show) | Lists the running containers. | | [`info`](#info) | Shows a running container's settings and live state. | | [`pid`](#pid) | Prints the PID of the container's init. | | [`scan`](#scan) | Re-registers running containers whose host-side records were lost. | | [`check`](#check) | Probes the kernel for everything Droidspaces uses. | | [`daemon`](#daemon) | Starts the background daemon. | | [`mode`](#mode) | Says whether commands go through a daemon. | | [`docs`, `help`, `version`](#docs-help-version) | The built-in guide, the flag summary, the version. | ## How it works - **The workspace** holds every container's config, PID file and logs: `/var/lib/Droidspaces` on Linux, `/data/local/Droidspaces` on Android. - **Flags are saved on `start`.** Each start writes the container's config, with the flags you gave, to `/Containers//container.config`, so later commands need only the name. See [The config file](#the-config-file). - **The daemon.** When `droidspaces daemon` is running, every command except `check`, `docs`, `help`, `version` and `mode` is handed to it. The daemon accepts root and members of the `droidspaces` group, so those users need no `sudo`. With no daemon, the binary does the work itself and needs root. `mode` tells you which case you are in. - **A running container answers for itself.** Commands read a running container's config from its monitor process, the config it booted with, so edits to `container.config` apply on the next start or restart. ## start ``` droidspaces --name=NAME --rootfs=DIR [flags] start # first start, from a directory droidspaces --name=NAME --rootfs-img=IMAGE [flags] start # first start, from an ext4 image droidspaces --name=NAME [flags] start # later starts, from the saved config droidspaces --config=FILE [flags] start # from a config file ``` Takes every flag in [Flags](#flags) and saves the ones that configure the container. A first start needs a name and a rootfs; after that the saved config supplies the rootfs. `start` takes one name only. It returns once the container's init is running, unless you pass `--foreground` from a terminal. ## stop ``` droidspaces --name=NAME stop # one container droidspaces --name=a,b,c stop # several, one after another ``` Asks the container's init to shut down the way its init system expects, waits up to 15 seconds, then kills it. ## restart ``` droidspaces --name=NAME [flags] restart ``` The container must be running. `restart` stops it and starts it again with nothing else able to act on it in between, and an image rootfs stays mounted, so it is fast. It reads `container.config` again, so edits made while the container ran take effect, and flags apply as on `start`. Running `reboot` inside the container boots it again with the config it started with, as LXC does, so edits wait for `restart`. ## enter ``` droidspaces --name=NAME enter # a root shell droidspaces --name=NAME enter USER # a login shell as USER ``` Logs in with the container's own `su -l USER`. Without `su`, it starts the user's shell from `/etc/passwd`, then the first of `/bin/bash`, `/bin/ash` and `/bin/sh` that exists. Through the daemon, `enter` needs a terminal. ## run ``` droidspaces --name=NAME run CMD [ARGS] # run a program droidspaces --name=NAME run 'CMD | CMD' # one argument with a space runs through /bin/sh -c droidspaces --name=NAME --user=USER run CMD # as another account, through su droidspaces --name=NAME --stdin run CMD < FILE # feed your input to the command ``` | Option | Meaning | |--------|---------| | `-u`, `--user=USER` | Run as this account, through the container's `su - USER -c`. Default: root. | | `--stdin` | Pass your input to the command. Through the daemon, a `run` outside a terminal reads nothing without it. | The command starts in `/`, with `/run/current-system/sw/bin` added to `PATH` for NixOS. A `--` right after `run` is dropped, the way `env` does. `run` exits with the command's own status, see [Exit codes](#exit-codes). ## show ``` droidspaces show # a table of running containers: name and PID droidspaces --json show # the same with OS, addresses, uptime, CPU and RAM ``` ## info ``` droidspaces --name=NAME info # settings and live state, as text droidspaces --name=NAME --json info # the same as JSON ``` The container must be running. ## pid ``` droidspaces --name=NAME pid # the PID of the container's init as the host sees it, or NONE ``` ## scan ``` droidspaces scan ``` Finds running containers whose host-side config or PID file was lost and registers them again, from what each container's monitor process holds: the config it booted with and its init PID. Nothing is read from inside a container. It also removes stale PID files, unmounts image rootfs mounts under `/mnt/Droidspaces` that no container uses any more, and warns about a container init with no monitor, with the `kill -KILL` command to stop it. Commands run a scan on their own when they cannot find a container by name. ## check ``` droidspaces check # the report, in must-have, recommended and optional groups droidspaces --json check # one 0 or 1 per probe, see JSON output ``` `check` needs no root and never goes through the daemon. Without root, `root` and several namespace and network probes report missing, so run it as root for the real answer. ## daemon ``` droidspaces daemon # start it in the background droidspaces daemon --foreground # stay attached, for a service manager ``` Needs root, and refuses to start when a daemon already answers. The systemd unit and the Android init service in `init/` both run `droidspaces daemon --foreground`. ## mode ``` droidspaces mode # prints daemon if a daemon is answering, otherwise direct ``` ## docs, help, version ``` droidspaces docs # the built-in guide: pages in a terminal, all of it when piped droidspaces help # every command and flag on one screen droidspaces version # the version, for example v7.2.0 ``` ## Flags Each flag that configures the container is saved in its config file on `start`, so it only has to be given once. [Container settings](Features.md) explains what each one does and when to use it; this table is the syntax. Old spellings still work: `--termux-x11` for `--x11` and `--allow-userns` for `--allow-sandboxing`. **Rootfs and identity** | Flag | Value | Config key | |------|-------|------------| | `-r`, `--rootfs` | directory with the rootfs | `rootfs_path` | | `-i`, `--rootfs-img` | ext4 image file or block device | `rootfs_path` | | `-n`, `--name` | container name; a comma-separated list for `stop` | `name` | | `-h`, `--hostname` | hostname inside the container, defaults to the name | `hostname` | | `-C`, `--conf`, `--config` | config file to load | | | `--reset` | reset the config to defaults, keeping name and rootfs | | | `--init` | absolute path of the init binary, no spaces, default `/sbin/init` | `custom_init` | | `-E`, `--env` | file of `KEY=value` lines, read again on every start, `enter` and `run`; a path with a `.` or `..` component is refused | `env_file` | | `-B`, `--bind`, `--bind-mount` | `SRC:DEST[:ro]`, repeatable or comma-separated | `bind_mounts` | **Networking** | Flag | Value | Config key | |------|-------|------------| | `--net` | `nat` (default), `gateway`, `macvlan`, `host`, `none` | `net_mode` | | `--nat-ip` | fixed address in `172.28.0.0/16`, NAT only | `static_nat_ip` | | `--upstream` | interfaces to send NAT traffic through, comma-separated, wildcards allowed; turns off auto-detection | `upstream_interfaces` | | `--port` | `HOST[:CONTAINER][/tcp\|udp\|tcp6\|udp6]`, default `tcp`, ranges as `a-b:a-b`, repeatable or comma-separated, NAT only | `port_forwards` | | `-d`, `--dns` | resolvers, comma-separated | `dns_servers` | | `-I`, `--disable-ipv6` | | `disable_ipv6` | | `--gateway`, `--gateway-container` | the running container that acts as router, required for gateway mode | `gateway_container` | | `--gateway-net` | LAN segment name, default `lan` | `gateway_net` | | `--gateway-iface` | the LAN interface's name inside the gateway, default `eth1` | `gateway_lan_ifname` | | `--gateway-bridge` | host bridge name, default `ds-` | `gateway_bridge` | | `--macvlan-parent` | host NIC, required for macvlan mode | `macvlan_parent` | | `--macvlan-mode` | `bridge` (default), `private`, `vepa`, `passthru` | `macvlan_mode` | **Hardware and integration** | Flag | Value | Config key | |------|-------|------------| | `-H`, `--hw-access` | | `enable_hw_access` | | `--allow-vts` | with `--hw-access`, leave the host's `tty1` to `tty6` visible | `allow_vts` | | `--gpu` | | `enable_gpu_mode` | | `-X`, `--x11` | | `enable_x11` | | `--tx11-flags` | Android only, extra arguments for Termux:X11 | `tx11_extra_flags` | | `--virgl` | Android only | `enable_virgl` | | `--virgl-flags` | Android only, extra arguments for the VirGL server | `virgl_extra_flags` | | `--pulse-audio` | Android only | `enable_pulseaudio` | | `--anland` | Android only, Wayland desktop through the Anland app | `enable_anland` | | `-S`, `--enable-android-storage` | Android only | `enable_android_storage` | **Resource limits, security and boot** | Flag | Value | Config key | |------|-------|------------| | `--memory` | size with `K`, `M`, `G` or `T`, minimum `4M` | `memory_limit`, in bytes | | `--allow-swap` | | `allow_swap` | | `--cpus` | cores, fractions allowed, minimum `0.01` | `cpu_quota` and `cpu_period`, in microseconds | | `--cpuset-cpus` | CPU numbers and ranges, such as `0-3,6`; empty removes the pin | `cpuset_cpus` | | `--pids-limit` | process count, 16 to 4194304 | `pids_limit` | | `-P`, `--selinux-permissive` | | `selinux_permissive` | | `--allow-sandboxing` | | `allow_sandboxing` | | `-V`, `--volatile` | | `volatile_mode` | | `--force-cgroupv1` | | `force_cgroupv1` | | `--privileged` | `nomask`, `nocaps`, `noseccomp`, `shared`, `full`, comma-separated | `privileged` | | `-f`, `--foreground` | attach your terminal to the container's console; Ctrl+Alt+Q stops the container. A start without a terminal turns it off | `foreground` | **Session flags**, not saved | Flag | What it does | |------|--------------| | `-u`, `--user` | The account `run` uses. | | `--stdin` | Pass your input to the `run` command. | | `--json` | JSON output from `show`, `info` and `check`. | ## The config file A plain `key=value` file, one key per line, with the keys from the tables above. Droidspaces reads one: the file named by `--config`; otherwise, when `--rootfs` or `--rootfs-img` is given, `container.config` in the directory that holds the rootfs; otherwise `/Containers//container.config`. `start` saves to the file it used and always to the workspace copy. ```ini name=web hostname=web rootfs_path=/var/lib/Droidspaces/Containers/web/rootfs.img net_mode=nat port_forwards=80:80/tcp,443:443/tcp bind_mounts=/srv/www:/var/www:ro memory_limit=1073741824 cpu_quota=200000 cpu_period=100000 allow_sandboxing=1 ``` Droidspaces writes booleans as `0` or `1`, and also reads `true`/`false`, `yes`/`no` and `on`/`off`. Keys the backend does not know, such as the app's `run_at_boot`, are kept in place. While a container runs, the config it booted with is visible inside it at `/run/droidspaces/container.config`. That copy is read-only and there for scripts inside the container: changing it has no effect, since the host never reads it. ## JSON output Every JSON output is one flat object on one line, with strings and integers only. Flags are `0` or `1`, and a limit of `0` means none. **`show --json`**, on a host with three containers installed and none running: ```json {"total":3,"ram_total_kb":16047624,"running":[]} ``` - `total`: the containers in the workspace, running or not. `ram_total_kb`: the host's memory. - `running`: one object per running container, with `name`, `pid`, `os` (the `PRETTY_NAME` from its `os-release`), `hostname`, `ip` and `ip6` (its addresses, comma-separated, without loopback and IPv6 link-local), `anland_sock`, `x11`, `uptime_sec`, `uptime` (as text), `ram_used_kb`, `cpu_permill` (its share of the host's CPU over 250 ms, 0 to 1000), `ram_limit_kb`, `cpu_limit_permill` (the share of the host's online CPUs it may use: its CPU limit or the cores its init may run on, such as a pin, whichever is less, 0 when that is all of them) and `swap_allowed`. **`info --json`** has one container's keys from `running` above, plus: - `host_platform` (`Android` or `Linux`), `host_arch`, `ram_total_kb`. - `networking_mode` (`NAT`, `host`, `none`, `gateway` or `macvlan`), then by mode: `nat_ip` and `upstream_interfaces`; `gateway_container`, `gateway_net`, `gateway_bridge` and `gateway_iface`; or `macvlan_parent` and `macvlan_mode`. - `disable_ipv6`, `hw_access` (`full`, `GPU` or `none`), and on Android `android_storage`, `tx11_flags`, `virgl`, `virgl_flags`, `pulseaudio` and `anland`. - `selinux` (`Permissive` or `Enforcing`) on a host with SELinux. - `volatile_mode`, `force_cgroup_v1`, `memory_limit` (bytes), `cpu_quota`, `cpu_period`, `cpuset_cpus` (the CPUs a pinned container runs on, empty when it is not pinned), `pids_limit`, `sandboxing_allowed`, `vts_allowed`, `foreground_mode`, `dns_servers`, `port_forwards`, `privileged_mode` (when set), `bind_mount_count`, `env_var_count`. Keys that do not apply are left out, and the limits are read from the container's cgroup, not from its config. **`check --json`**, run without root, trimmed: ```json {"root":0,"kernel_version":1,"pid_ns":0,"mnt_ns":0, ... ,"user_ns":1,"version":"7.2.0","requirements_met":0} ``` One key per probe: `root`, `kernel_version`, `pid_ns`, `mnt_ns`, `uts_ns`, `ipc_ns`, `pivot_root`, `procfs`, `sysfs`, `seccomp` are required; `epoll`, `signalfd`, `pty`, `devpts`, `loop`, `ext4`, `cgroup2`, `cgroup_ns`, `mount_api`, `devtmpfs` are recommended; `fuse`, `tun`, `overlayfs`, `net_ns`, `bridge`, `veth`, `macvlan`, `ipv6_nat`, `memory_limit`, `swap_limit`, `cpu_limit`, `cpu_accounting`, `pids_limit`, `cpu_pinning`, `user_ns` are optional. `requirements_met` is `1` when every required probe passed. ## Examples ```bash # A first container from an image, with a port forwarded sudo droidspaces --name=web --rootfs-img=/srv/web.img --port=8080:80 start # Later starts need only the name sudo droidspaces --name=web start # Watch the boot on the console sudo droidspaces --name=web --foreground start # A shell as a user, and a one-off command with a pipe sudo droidspaces --name=web enter alice sudo droidspaces --name=web run sh -c 'ps aux | grep nginx' # A script piped into the container sudo droidspaces --name=web --stdin run sh -s < setup.sh # An OpenWrt router and a client that lives behind it sudo droidspaces --name=openwrt --rootfs=/srv/openwrt --net=nat start sudo droidspaces --name=kali --rootfs=/srv/kali --net=gateway --gateway=openwrt start # A container on the wired LAN with its own address sudo droidspaces --name=ubuntu --rootfs=/srv/ubuntu --net=macvlan --macvlan-parent=eth0 start # Try something without keeping it sudo droidspaces --name=scratch --rootfs=/srv/ubuntu --volatile start # What is running, as JSON sudo droidspaces --json show ``` ## Where things are `` in a path has its spaces turned into dashes. | Path | Contents | |------|----------| | `/Containers//` | the container's config and, for app-installed containers, its rootfs | | `/Logs//log` | the log of each start, stop and restart | | `/Logs/droidspacesd.log` | the daemon's log | | `/mnt/Droidspaces/` | where an image rootfs is mounted while the container runs | ## Exit codes | Code | Meaning | |------|---------| | `0` | Success. `check` always exits `0`: read `requirements_met` instead. | | `1` | A bad option or command, no root, a container name that was not found, `pid` printing `NONE`, a failed container in a `stop` list, a daemon that refused you. | | `255` | `start`, `stop` or `restart` failed, or `info`, `enter` or `run` found the container not running. | `run` and `enter` exit with the command's or the shell's own status instead: `128` plus the signal number when it was killed, `127` when the command does not exist, `126` when it exists but cannot run. A command that exits `255` itself looks the same as a failure of Droidspaces. --- Previous: [Container settings](Features.md) | Next: [Display, audio and desktop](Graphics-and-Audio.md)