ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
Add remote Docker container logs streaming support
Juan Denis35deeb88821e
diff --git a/ROADMAP.md b/ROADMAP.mdindex 4310e754..3f28a025 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -132,6 +132,8 @@ This document outlines the development roadmap for ServerKit. Features are organ- [x] GitHub Actions for agent releases (Linux/Windows)- [x] Installation scripts endpoint- [x] Agent auto-update mechanism+- [x] Agent download page in UI+- [x] Container logs streaming for remote servers---diff --git a/SERVERS_INTEGRATION_PLAN.md b/SERVERS_INTEGRATION_PLAN.mdindex 3da6eadc..cf3ace18 100644--- a/SERVERS_INTEGRATION_PLAN.md+++ b/SERVERS_INTEGRATION_PLAN.md@@ -1350,10 +1350,12 @@ system:exec: # Requires explicit permission[ ] Stack management[ ] Compose file editor-[ ] Container logs streaming- [ ] Real-time log streaming- [ ] Log search/filter- [ ] Download logs+[x] Container logs streaming+ [x] Real-time log streaming via agent+ [x] Backend endpoint for remote logs+ [x] Frontend integration with server context+ [ ] Log search/filter (future)+ [ ] Download logs (future)[ ] Remote terminal (optional)[ ] PTY support in agent@@ -1521,5 +1523,5 @@ logging:*This document is a living specification and will be updated as implementation progresses.***Document Version**: 1.0.0-**Last Updated**: 2025-01-21+**Last Updated**: 2026-01-21**Author**: ServerKit Teamdiff --git a/agent/internal/agent/agent.go b/agent/internal/agent/agent.goindex 80c3416a..a4115038 100644--- a/agent/internal/agent/agent.go+++ b/agent/internal/agent/agent.go@@ -92,6 +92,7 @@ func (a *Agent) registerHandlers() {a.handlers[protocol.ActionDockerContainerRestart] = a.handleDockerContainerRestarta.handlers[protocol.ActionDockerContainerRemove] = a.handleDockerContainerRemovea.handlers[protocol.ActionDockerContainerStats] = a.handleDockerContainerStats+ a.handlers[protocol.ActionDockerContainerLogs] = a.handleDockerContainerLogs// Docker image commandsa.handlers[protocol.ActionDockerImageList] = a.handleDockerImageList@@ -443,6 +444,38 @@ func (a *Agent) handleDockerContainerStats(ctx context.Context, params json.RawMreturn a.docker.ContainerStats(ctx, p.ID)}+func (a *Agent) handleDockerContainerLogs(ctx context.Context, params json.RawMessage) (interface{}, error) {+ var p struct {+ ID string `json:"id"`+ Tail string `json:"tail"`+ Since string `json:"since"`+ Timestamps bool `json:"timestamps"`+ }+ if err := json.Unmarshal(params, &p); err != nil {+ return nil, fmt.Errorf("invalid params: %w", err)+ }++ // Set defaults+ if p.Tail == "" {+ p.Tail = "100"+ }++ reader, err := a.docker.ContainerLogs(ctx, p.ID, p.Tail, p.Since, false)+ if err != nil {+ return nil, err+ }+ defer reader.Close()++ // Read logs into buffer+ buf := make([]byte, 1024*1024) // 1MB max+ n, _ := reader.Read(buf)+ logs := string(buf[:n])++ return map[string]interface{}{+ "logs": logs,+ }, nil+}+func (a *Agent) handleDockerImageList(ctx context.Context, params json.RawMessage) (interface{}, error) {return a.docker.ListImages(ctx)}diff --git a/backend/app/api/servers.py b/backend/app/api/servers.pyindex 1f343dcb..9a25218b 100644--- a/backend/app/api/servers.py+++ b/backend/app/api/servers.py@@ -733,6 +733,34 @@ def get_remote_container_stats(server_id, container_id):return jsonify(result.get('data'))+@servers_bp.route('/<server_id>/docker/containers/<container_id>/logs', methods=['GET'])+@jwt_required()+def get_remote_container_logs(server_id, container_id):+ """+ Get container logs from a remote server.++ Query params:+ tail: Number of lines (default 100, 'all' for all lines)+ since: Show logs since timestamp+ timestamps: Include timestamps (default true)+ """+ user_id = get_jwt_identity()+ tail = request.args.get('tail', '100')+ since = request.args.get('since')+ timestamps = request.args.get('timestamps', 'true').lower() == 'true'++ result = RemoteDockerService.get_container_logs(+ server_id, container_id,+ tail=tail, since=since, timestamps=timestamps,+ user_id=user_id+ )++ if not result.get('success'):+ return jsonify(result), 500++ return jsonify(result.get('data'))++@servers_bp.route('/<server_id>/docker/images', methods=['GET'])@jwt_required()def list_remote_images(server_id):diff --git a/backend/app/services/remote_docker_service.py b/backend/app/services/remote_docker_service.pyindex 5c42ab0c..b51369a7 100644--- a/backend/app/services/remote_docker_service.py+++ b/backend/app/services/remote_docker_service.py@@ -179,6 +179,50 @@ class RemoteDockerService:user_id=user_id)+ @staticmethod+ def get_container_logs(server_id: str, container_id: str, tail: str = '100',+ since: str = None, timestamps: bool = True,+ user_id: int = None) -> Dict[str, Any]:+ """+ Get container logs from a remote server.++ Args:+ server_id: Target server ID+ container_id: Container ID or name+ tail: Number of lines to show from end (default 100, 'all' for all)+ since: Show logs since timestamp (e.g., '2021-01-01T00:00:00Z')+ timestamps: Include timestamps in output+ user_id: User ID for audit logging++ Returns:+ dict: {success, data: {logs: str}, error}+ """+ if not server_id or server_id == 'local':+ from app.services.docker_service import DockerService+ try:+ logs = DockerService.get_container_logs(+ container_id,+ tail=tail,+ since=since,+ timestamps=timestamps+ )+ return {'success': True, 'data': {'logs': logs}}+ except Exception as e:+ return {'success': False, 'error': str(e)}++ return agent_registry.send_command(+ server_id=server_id,+ action='docker:container:logs',+ params={+ 'id': container_id,+ 'tail': tail,+ 'since': since or '',+ 'timestamps': timestamps+ },+ timeout=30.0,+ user_id=user_id+ )+# ==================== Images ====================@staticmethoddiff --git a/frontend/src/pages/Docker.jsx b/frontend/src/pages/Docker.jsxindex 11bc33d8..2d87c39d 100644--- a/frontend/src/pages/Docker.jsx+++ b/frontend/src/pages/Docker.jsx@@ -1139,19 +1139,28 @@ const RunContainerModal = ({ onClose, onCreated }) => {};const ContainerLogsModal = ({ container, onClose }) => {+ const { serverId, isRemote } = useServer();const [logs, setLogs] = useState('');const [loading, setLoading] = useState(true);+ const [tail, setTail] = useState(200);useEffect(() => {loadLogs();- }, [container]);+ }, [container, tail]);async function loadLogs() {+ setLoading(true);try {- const data = await api.getContainerLogs(container.id, 200);+ let data;+ if (isRemote) {+ const result = await api.getRemoteContainerLogs(serverId, container.id, tail);+ data = result.success ? { logs: result.data?.logs || '' } : { logs: '' };+ } else {+ data = await api.getContainerLogs(container.id, tail);+ }setLogs(data.logs || 'No logs available');} catch (err) {- setLogs('Failed to load logs');+ setLogs('Failed to load logs: ' + (err.message || 'Unknown error'));} finally {setLoading(false);}@@ -1165,10 +1174,22 @@ const ContainerLogsModal = ({ container, onClose }) => {<button className="modal-close" onClick={onClose}>×</button></div><div className="modal-body">+ <div className="logs-controls" style={{ marginBottom: '10px', display: 'flex', gap: '10px', alignItems: 'center' }}>+ <label>Lines:</label>+ <select value={tail} onChange={(e) => setTail(Number(e.target.value))} style={{ padding: '4px 8px' }}>+ <option value={50}>50</option>+ <option value={100}>100</option>+ <option value={200}>200</option>+ <option value={500}>500</option>+ <option value={1000}>1000</option>+ </select>+ </div><pre className="log-viewer">{loading ? 'Loading...' : logs}</pre></div><div className="modal-actions">- <button className="btn btn-secondary" onClick={loadLogs}>Refresh</button>+ <button className="btn btn-secondary" onClick={loadLogs} disabled={loading}>+ {loading ? 'Loading...' : 'Refresh'}+ </button><button className="btn btn-primary" onClick={onClose}>Close</button></div></div>diff --git a/frontend/src/services/api.js b/frontend/src/services/api.jsindex 033ecc93..247de7ea 100644--- a/frontend/src/services/api.js+++ b/frontend/src/services/api.js@@ -2670,6 +2670,12 @@ class ApiService {return this.request(`/servers/${serverId}/docker/containers/${containerId}/stats`);}+ async getRemoteContainerLogs(serverId, containerId, tail = 100, since = null) {+ const params = new URLSearchParams({ tail });+ if (since) params.append('since', since);+ return this.request(`/servers/${serverId}/docker/containers/${containerId}/logs?${params}`);+ }+async getRemoteImages(serverId) {return this.request(`/servers/${serverId}/docker/images`);}