Running Commands in Development

Spin makes it easy to run commands in your development environment by following the Docker Compose CLI syntax.

How to run commands in development

You have two options to run commands in your development environment:

  1. spin exec - This executes commands in an EXISTING container (and requires that service to be already running with spin up).
  2. spin run - This executes commands in a NEW container, then exits.

For example, let's say you want to run composer install in your development environment for Laravel, you would use the following command:

Run a command in a new container

# Usage: spin run <service> <command>
spin run php composer install

Execute a command in an existing container

# Usage: spin exec <service> <command>
spin exec php composer install

Take note of the syntax. You specify the service you want to run the command in, then the command you want to run. The same is true for spin exec.

When to use spin exec vs spin run

In development, it's often easier to use spin run because it will create a new container and then exit. This is faster than having to start the container with spin up and then use spin exec.

If you have something that you specifically need to run in an already running container, then you should use spin exec.