Running Spin Applications

Once you have created and built your application, it’s ready to run. To run an application, use the spin up command.

Specifying the Application to Run

By default, spin up looks for a file named spin.toml in the current directory.

If your manifest is named something different, or isn’t in your current directory, use the -f (--from) flag. You also use -f to run remote applications.

-f Valuespin up Behavior
File name: -f demo.tomlRuns the specified manifest file
Directory name: -f demo/Looks for a spin.toml file in that directory and runs that
Registry reference: -f ghcr.io/fermyon/example:v1Pulls the application from the registry and runs that

If Spin misunderstands a registry reference as a file name, or vice versa, you can use --from-file or --from-registry instead of -f to disambiguate.

If you see the error failed to resolve content at "example.wasm" (where example.wasm is the module file of a component), check that the application has been built.

If your application doesn’t run, you can run spin doctor to check for problems with your Spin configuration and tools.

Testing HTTP Applications

By default, HTTP applications listen on localhost:3000. You can override this with the --listen option. Spin prints links to the application components to make it easy to open them in the browser or copy them to curl commands for testing.

Application Output

By default, Spin prints application output, and any of its own error messages, to the console.

To hide application output, pass the --quiet flag:

$ spin up --quiet

To limit application output to specific components, pass the --follow flag:

$ spin up --follow cart --follow cart-api

Persistent Logs

By default:

  • If you run an application from the file system (a TOML file), Spin saves a copy of the application output and error messages. This is saved in the .spin/logs directory, under the directory containing the manifest file.
  • If you run an application from a registry reference, Spin does not save a copy of the application output and error messages; they are only printed to the console.

To control logging, pass the --log-dir flag. The logs will be saved to the specified directory (no matter whether the application is local or remote):

$ spin up --log-dir ~/dev/bugbash

If you prefer not to have the stdout and stderr of your application’s components written to disk (as in the example above), you can pass the --log-dir flag with an empty string, like this:

$ spin up --log-dir ""

Trigger-Specific Options

Some trigger types support additional spin up flags. For example, HTTP applications can have a --listen flag to specify an address and port to listen on. See the HTTP trigger and Redis trigger pages for more details.

Monitoring Applications for Changes

Spin’s watch command rebuilds and restarts Spin applications whenever files change. You can use the spin watch command in place of the spin build and spin up commands, to build, run and then keep your Spin application running without manual intervention while staying on the latest code and files.

The watch command accepts valid Spin up options and passes them through to spin up for you when running/rerunning the Spin application. E.g. spin watch --listen 127.0.0.1:3001

By default, Spin watch monitors:

  • The application manifest (spin.toml file)
  • Any files specified in the component.(id).build.watch sections of the spin.toml file
  • Any files specified in the component.(id).files sections of the spin.toml file
  • The files specified in the component.(id).source sections of the spin.toml file

If any of these change, Spin will rebuild the application if necessary, then restart the application with the new files.

Spin watch does not consider changes to a file’s metadata (file permissions or when it was last modified) as a change.

The following spin.toml configuration (belonging to a Spin http-rust application) is configured to ensure that the application is both rebuilt (via cargo build --target wasm32-wasi --release) and rerun whenever changes occur in any Rust source (.rs) files, the Cargo.toml file or the spin.toml file, itself. When changes occur in either the Wasm binary file (target/wasm32-wasi/release/test.wasm) or the text file (my-files/changing-file.txt) the application is only rerun using the initial spin up command:

[component.test]
// -- snip
files = ["my-files/changing-file.txt"]
source = "target/wasm32-wasi/release/test.wasm"
[component.test.build]
command = "cargo build --target wasm32-wasi --release"
# Example watch configuration for a Rust application
watch = ["src/**/*.rs", "Cargo.toml"]

If the build section specifies a workdir, then watch patterns are relative to that directory. Otherwise, watch patterns are relative to the directory containing the spin.toml file.

If you would prefer Spin watch to only rerun the application (without a rebuild) when changes occur, you can use the --skip-build option when running the spin watch command. In this case, Spin will ignore the component.(id).build.watch section, and monitor only the spin.toml, component.source and component.files.

The table below outlines exactly which files spin watch will monitor for changes depending on how you run the command. spin watch uses the configuration found on every component in your application.

Filesspin watch monitors for changesspin watch --skip-build monitors for changes
Application manifest spin.tomlYesYes
Component build.watchYesNo
Component filesYesYes
Component sourceNo (Yes if the component has no build command)Yes

Spin watch waits up to 100 milliseconds before responding to filesystem events, then processes all events that occurred in that interval together. This is so that if you make several changes close together (for example, using a Save All command), you get them all processed in one rebuild/reload cycle, rather than going through a cycle for each one. You can override the interval by passing in the --debounce option; e.g. spin watch --debounce 1000 will make Spin watch respond to filesystem events at most once per second.

Note: If the build step (spin build) fails, spin up will not be re-run, and the previous version of the app will remain.

Passing the --clear flag clears the screen anytime a rebuild or rerun occurs. Spin watch does not clear the screen between rebuild and rerun as this provides you with an opportunity to see any warnings.

For additional information about Spin’s watch feature, please see the Spin watch - live reload for Wasm app development blog article.

The application manifests shown in the blog post are the version 1 manifest, but the content applies equally to the version 2 format.

The Always Build Option

Some people find it frustrating having to remember to build their applications before running spin up. If you want to always build your projects when you run them, set the SPIN_ALWAYS_BUILD environment variable in your profile or session. If this is set, spin up runs spin build before starting your applications.

Next Steps