kratos run command runs your Kratos project locally using go run, automatically detecting your application’s entry point.
Usage
Description
This command provides a convenient way to run your Kratos service during development. It automatically:- Searches for the
cmd/directory in your project - Detects available entry points
- Prompts you to select one if multiple are found
- Executes
go runwith the appropriate directory
Arguments
directory(optional) - Specific directory containing the main package to run. If not provided, the command searches forcmd/directories automatically.program-args(optional) - Arguments to pass to your program. Separate these from command flags using--.
Flags
Target working directory for the running application. This changes the working directory before executing the program.
Auto-detection
When you runkratos run without arguments, the command:
- Searches for directories under
cmd/in your project - If one entry point is found, runs it automatically
- If multiple entry points exist, presents an interactive selection menu
- Searches up to 5 parent directories to find
go.modandcmd/
Examples
Basic Usage
Run the project from the project root:cmd/myservice/, it runs automatically.
Multiple Services
For a project with multiple services:Specify Directory
Run a specific service directly:Pass Arguments to Program
Pass configuration or other arguments to your application:Change Working Directory
Run the service with a different working directory:Combined Flags and Arguments
How It Works
Thekratos run command essentially executes:
cmd/myservice, it runs:
Project Structure
The command works with standard Kratos project structure:Common Use Cases
Development Workflow
Debug Mode
Multiple Configuration Files
Run from Subdirectory
The command searches parent directories forcmd/, so you can run it from anywhere in your project:
Troubleshooting
Error: The cmd directory cannot be found
Error: The cmd directory cannot be found
The command searches up to 5 levels for a
cmd/ directory. Ensure:- You’re within your project directory
- Your project has a
cmd/directory - Your
cmd/directory contains subdirectories with main packages
No prompt appears with multiple services
No prompt appears with multiple services
If you have multiple services but want to run a specific one without the prompt:
Arguments not being passed correctly
Arguments not being passed correctly
Always use
-- to separate command flags from program arguments:The
kratos run command is intended for development use. For production deployments, build your application binary and run it directly.Related Commands
kratos new- Create a new project to run- Build your project:
go build -o ./bin/ ./...