`application.readLogs` with `search` returns HTTP 500 when there are no matches, and only searches inside the last `tail` lines
Describe the bug
application.readLogs (same pattern in the other readLogs routers) builds this command in
packages/server/src/services/docker.ts → getContainerLogs:
docker container logs --timestamps --tail ${tail} ${sinceFlag} ${target} 2>&1 | grep -iF '${search}'
This has two problems:
- No matches → HTTP 500 instead of an empty result.
grepexits with code 1 when it finds nothing (code 1 means "no lines selected", not an error).execAsyncrejects on any non-zero exit code, and thecatchonly recovers whenstdoutis non-empty, so an empty search result is re-thrown and the API answers500 Internal Server Error. searchonly looks inside the lasttaillines.--tailis applied bydocker logsbefore the pipe togrep, so a line that exists in the container log but is older than the lasttaillines (default 100) is never found — and, because of (1), the user gets a 500 instead of "nothing found". In practice, searching for anything that happened at container start-up fails as soon as the app has logged ~100 lines since.
To Reproduce
Dokploy v0.30.8, application deployed as a swarm service / container. Example container log (abridged, timestamps as returned by Dokploy):
2026-10-07T04:39:19Z Prisma schema loaded from db/prisma/schema.prisma
2026-10-07T04:39:19Z Applying migration `20261007000000_example`
2026-10-07T04:39:19Z All migrations have been successfully applied.
2026-10-07T04:39:22Z [PrismaService] Prisma client connected
... ~100 more lines (route mapping, requests, cron logs) ...
2026-10-07T05:00:00Z [ImportProcessor] Scheduled import triggered
2026-10-07T05:00:03Z [ImportService] Scheduled import finished
Calls to GET /api/application.readLogs (via the API / MCP), all on the same application:
| # | Parameters | Expected | Actual |
|---|---|---|---|
| 1 | tail: 5, since: "10m" (no search, nothing logged in the period) |
"" |
✅ "" |
| 2 | tail: 50, search: "textthatdoesnotexist" |
"" |
❌ 500 |
| 3 | tail: 5, since: "24h", search: "Prisma" (lines exist, but ~100 lines up) |
the 4 "Prisma" lines | ❌ 500 |
| 4 | tail: 2000, since: "24h", search: "Prisma" |
the 4 "Prisma" lines | ✅ 4 lines |
| 5 | tail: 5, search: "Import" (matches are among the last 5 lines) |
2 lines | ✅ 2 lines |
Cases 2 and 3 are the bug; 4 is the current workaround (a large tail).
Expected behavior
- A search with no matches returns an empty string (HTTP 200), like case 1.
searchfilters the log first andtaillimits the number of matching lines returned, sotail: 100, search: "migration"means "the last 100 lines that containmigration".
Suggested fix
const command = search
? `${baseCommand.replace(`--tail ${tail} `, "")} 2>&1 | grep -iF '${escapedSearch}' | tail -n ${tail}`
: `${baseCommand} 2>&1`;
and treat grep's "no match" as an empty result, e.g. append || true to the grep stage, or in the
catch return "" when the error's exit code === 1 and stderr is empty.
(If scanning the whole log is a concern for very large logs, keep a generous upper bound such as
--tail 10000 on docker logs and apply the user's tail after grep.)
Environment
- Dokploy: v0.30.8 (latest at the time of writing)
- Deployment: single server, swarm service
- Affected endpoints:
application.readLogsand the equivalentreadLogsin the other routers (compose,postgres,redis,mysql,mariadb,mongo,libsql) that callgetContainerLogswithsearch.
Question
Could you confirm whether this is something you plan to fix, or let us know the recommended way to search a container's start-up logs through the
API in the meantime? Today our workaround is to always pass tail: 2000 together with search.