Skip to main content

Get Container Logs

GET /api/containers/{id}/logs?env=1&tail=100
Retrieves the most recent log entries from a container. Returns logs as a single response.

Path Parameters

id
string
required
The container ID or name

Query Parameters

env
string
required
The environment ID where the container is located
tail
number
default:"100"
Number of lines to retrieve from the end of the logs

Response

logs
string
The container log output as a string

Error Responses

error
string
Error message if the request fails
details
string
Additional error details
Status Codes:
  • 200 - Success
  • 403 - Permission denied
  • 500 - Failed to get container logs

Example

curl -X GET "https://your-dockhand.com/api/containers/abc123def456/logs?env=1&tail=100" \
  -H "Cookie: session=your-session-cookie"

Response Example

{
  "logs": "2024-01-15T10:30:00.000Z Starting application...\n2024-01-15T10:30:01.000Z Server listening on port 3000\n2024-01-15T10:30:15.000Z GET /api/health 200\n"
}

Stream Container Logs

GET /api/containers/{id}/logs/stream?env=1&tail=100
Streams container logs in real-time using Server-Sent Events (SSE). This endpoint provides live log output as the container generates it.

Path Parameters

id
string
required
The container ID or name

Query Parameters

env
string
required
The environment ID where the container is located
tail
number
default:"100"
Number of historical log lines to retrieve before starting the stream

Response Format

The endpoint returns a Server-Sent Events (SSE) stream with the following event types: Event: connected Emitted immediately when the stream connection is established.
containerId
string
The container ID
containerName
string
The container name
hasTty
boolean
Whether the container has TTY enabled
Event: log Emitted for each log line from the container.
text
string
The log line text
containerName
string
The container name
stream
string
The output stream - either “stdout” or “stderr” (only present for non-TTY containers)
Event: end Emitted when the log stream ends (e.g., container stopped).
reason
string
Reason the stream ended
Event: error Emitted if an error occurs during streaming.
error
string
Error message

Error Responses

Status Codes:
  • 200 - SSE stream established
  • 403 - Permission denied
  • 503 - Edge agent not connected (for Hawser Edge environments)

Example

curl -X GET "https://your-dockhand.com/api/containers/abc123def456/logs/stream?env=1&tail=100" \
  -H "Cookie: session=your-session-cookie" \
  -H "Accept: text/event-stream"

Response Example

event: connected
data: {"containerId":"abc123def456","containerName":"my-nginx","hasTty":false}

event: log
data: {"text":"2024-01-15T10:30:00.000Z Starting application...\n","containerName":"my-nginx","stream":"stdout"}

event: log
data: {"text":"2024-01-15T10:30:01.000Z Server listening on port 3000\n","containerName":"my-nginx","stream":"stdout"}

event: log
data: {"text":"2024-01-15T10:30:15.000Z GET /api/health 200\n","containerName":"my-nginx","stream":"stdout"}

: keepalive

event: log
data: {"text":"2024-01-15T10:30:30.000Z Warning: High memory usage\n","containerName":"my-nginx","stream":"stderr"}

Notes

  • Keepalive comments (: keepalive) are sent every 5 seconds to maintain the connection through proxies like Traefik
  • For containers with TTY enabled, the stream field is not present in log events
  • For non-TTY containers, Docker multiplexes stdout and stderr which are demultiplexed by the API
  • The stream follows logs in real-time until the client disconnects or the container stops
  • Both stdout and stderr streams are included in the output
  • Timestamps are included if the container was configured with --log-opt timestamps=true

Build docs developers (and LLMs) love