Execute a command inside a running nSelf service container by service name.
# Open an interactive shell in the Postgres container
nself exec db bash
# Run a one-off psql query
nself exec db psql -U postgres -c "SELECT count(*) FROM np_users;"
# Tail Hasura logs live
nself exec api tail -f /var/log/hasura/server.lognself exec <SERVICE> [COMMAND...] [FLAGS]nself exec is the nSelf-aware equivalent of docker exec. It resolves the service name to the correct container using the active environment and project name, so you never need to look up the full container ID or prefix.
When COMMAND is omitted, the command defaults to an interactive shell (bash or sh, whichever is available in the container). The terminal is allocated a pseudo-TTY automatically unless --no-tty is passed.
Service names match the entries in nself status: db,api, auth, storage, search,mail, redis, admin. Custom services use theCS_N key from your env file or the service alias if you have set one.
| Name | Service | Notes |
|---|---|---|
db | PostgreSQL | Always available |
api | Hasura GraphQL | Always available |
auth | nHost Auth | Always available |
nginx | Nginx | Always available |
storage | MinIO | Optional service |
redis | Redis | Optional service |
search | MeiliSearch | Optional service |
mail | Mailpit (dev) / SMTP relay | Optional service |
admin | nself-admin | Optional service |
cs1…cs10 | Custom services | Alias: value of NSELF_CS_N_ALIAS env var |
| Flag | Type | Default | Description |
|---|---|---|---|
--no-tty | bool | false | Disable pseudo-TTY allocation (use for scripted/piped commands) |
--user | string | Run as a specific user inside the container | |
--env | string | active | Target environment: local, staging, prod |
--workdir | string | Override the working directory inside the container |
nself exec db psql -U postgresnself exec db psql -U postgres -d nself -f /migrations/001_add_index.sqlnself exec api cat /hasura/metadata/tables.yamlnself exec redis redis-cli info memorynself exec db --no-tty psql -U postgres -c "\l" | grep nselfnself exec db --user postgres bash# If CS_1 alias is "ping_api"
nself exec ping_api shnself exec db --env staging psql -U postgres -c "SELECT version();"NSELF_ENV — default target environment when --env is not specified0 — command completed successfully1 — generic error (service not found, container not running)2 — invalid arguments