Commands
Endor allows you to run a command inside a sandbox and retrieve the result back. This command is executed when the sandbox is ready and has been successfully started.
If you have mounted Volumes, or have allowed Networking access to the sandbox, Volumes and Networking access are available when the command is executed.
Running a command
Run a command that succeeds
- 1
Start any service with the
--command
flag:Terminal window endor run alpine --command 'cat /etc/os-release' - 2
Check the result command execution:
๐ EndorLaunching the Alpine environment๐จ Environment stoppedโญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎโ Alpine Connection Details โโ โโ No active connection. โโฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏCommand Result:โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎโ Return Code: 0 โโ Output: โโ NAME="Alpine Linux" โโ ID=alpine โโ VERSION_ID=3.22.0 โโ PRETTY_NAME="Alpine Linux v3.22" โโ HOME_URL="https://alpinelinux.org/" โโ BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues" โโฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ - 3
Test that the exit code of the executed command has been propagated
Terminal window # In your hostecho $?
However, if you run a command that fails its execution, the exit code of that command will be forwarded to the Endor CLI exit code:
Run a command that fails
- 1
Run a command that will fail:
Terminal window endor run alpine --command 'ls -la /does-not-exist' - 2
Check the result command execution:
๐ EndorLaunching the Alpine environment๐จ Environment stoppedโญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎโ Alpine Connection Details โโ โโ No active connection. โโฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏCommand Result:โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎโ Return Code: 1 โโ Error Output: โโ ls: /does-not-exist: No such file or directory โโฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ - 3
Test that the exit code of the executed command has been propagated
Terminal window # In your hostecho $?
Initialization commands
Before the main service (or the command, if provided) is executed, multiple initialization commands can be provided. They will run right after Volumes have been mounted (if any), and after Network access has been granted (if enabled.)
Run an initialization command
- 1
Run any service with the
--init-command
flag.Terminal window endor run alpine \--init-command 'touch /opt/file-a' \--init-command 'touch /opt/file-b' \--command 'ls -la /opt' - 2
Check the result command execution:
๐ EndorLaunching the Alpine environment๐จ Environment stoppedโญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎโ Alpine Connection Details โโ โโ No active connection. โโฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏCommand Result:โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎโ Return Code: 0 โโ Output: โโ total 3 โโ drwxr-xr-x 2 root root 0 May 30 12:13 . โโ drwxrwxrwx 20 root root 0 Jun 26 12:06 .. โโ -rw-r--r-- 1 root root 0 Jul 16 11:16 file-a โโ -rw-r--r-- 1 root root 0 Jul 16 11:16 file-b โโฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ - 3
Test that the exit code of the executed command has been propagated
Terminal window # In your hostecho $?
Common Use Cases
Run initialization commands if you need to:
- Pre-install applications: if you need certain applications to be started before the main environment runs, or before your provided command executes, you can use initialization commands to make sure that these packages are installed in the system.
Pre-install applications
- 1
Pre-install applications, and use them in the
--command
:Terminal window endor run alpine \--allow-net \--init-command 'apk update' \--init-command 'apk add figlet' \--command 'figlet "Hello, Endor!"' - 2
Check the result command execution:
๐ EndorLaunching the Alpine environment๐จ Environment stoppedโญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎโ Alpine Connection Details โโ โโ No active connection. โโฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏCommand Result:โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎโ Return Code: 0 โโ Output: โโ _ _ _ _ _____ _ _ โโ | | | | ___| | | ___ | ____|_ __ __| | ___ _ __| | โโ | |_| |/ _ \ | |/ _ \ | _| | '_ \ / _` |/ _ \| '__| | โโ | _ | __/ | | (_) | | |___| | | | (_| | (_) | | |_| โโ |_| |_|\___|_|_|\___( ) |_____|_| |_|\__,_|\___/|_| (_) โโ |/ โโฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Initialization scripts
In the same way that itโs possible to provide initialization commands, Endor also supports to provide a list of initialization scripts. Initialization scripts are files present in your host machine.
Initialization scripts are allowed to fail. Endor will continue with the following initialization scripts, and ultimately, will run the service normally, or the command that was provided, if any. If an initialization script fails, this event will be logged by Endor.
Run an initialization script
- 1
Create a script that performs some initialization logic, and that resides in your host filesystem:
Terminal window cat <<EOF > init-sandbox.shtouch /opt/file-atouch /opt/file-bEOF - 2
Run any service with the
--init-script
flag pointing to the path in your filesystem.Terminal window endor run alpine --init-script ./init-sandbox.sh --command 'ls -la /opt' - 3
Check the result command execution:
๐ EndorLaunching the Alpine environment๐จ Environment stoppedโญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎโ Alpine Connection Details โโ โโ No active connection. โโฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏCommand Result:โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎโ Return Code: 0 โโ Output: โโ total 3 โโ drwxr-xr-x 2 root root 0 May 30 12:13 . โโ drwxrwxrwx 20 root root 0 Jun 26 12:06 .. โโ -rw-r--r-- 1 root root 0 Jul 16 11:36 file-a โโ -rw-r--r-- 1 root root 0 Jul 16 11:36 file-b โโฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Common Use Cases
Run initialization scripts if you need to:
- Initialize environments from an existing script: you can easily initialize environments with a provided script (e.g. lives inside your project repository). This is useful for teams that need to run common scripts before the environment initializes.
Format
If you prefer to have no decorations, you can use the plain
format. The plain
format will:
- Forward the sandbox
stdout
to the Endor CLIstdout
. - Forward the sandbox
stderr
to the Endor CLIstderr
, along with Endor specific logging messages. - Forward the exit code of the sandbox execution.
Plain format output
- 1
Run any service with the
--format
flag set toplain
.Terminal window endor run alpine --format plain --command 'cat /etc/os-release' 2> /dev/null - 2
Check the result command execution:
NAME="Alpine Linux"ID=alpineVERSION_ID=3.22.0PRETTY_NAME="Alpine Linux v3.22"HOME_URL="https://alpinelinux.org/"BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues" - 3
Test that the exit code of the executed command has been propagated
Terminal window # In your hostecho $?