ruby_llm-docker 0.0.1 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +255 -11
- data/Rakefile +3 -3
- data/examples/docker_chat.rb +228 -0
- data/examples/list_containers.rb +36 -0
- data/examples/test_chat.rb +81 -0
- data/lib/ruby_llm/docker/build_image.rb +111 -0
- data/lib/ruby_llm/docker/copy_to_container.rb +196 -0
- data/lib/ruby_llm/docker/create_container.rb +146 -0
- data/lib/ruby_llm/docker/create_network.rb +131 -0
- data/lib/ruby_llm/docker/create_volume.rb +129 -0
- data/lib/ruby_llm/docker/exec_container.rb +185 -0
- data/lib/ruby_llm/docker/fetch_container_logs.rb +132 -0
- data/lib/ruby_llm/docker/list_containers.rb +59 -0
- data/lib/ruby_llm/docker/list_images.rb +79 -0
- data/lib/ruby_llm/docker/list_networks.rb +81 -0
- data/lib/ruby_llm/docker/list_volumes.rb +88 -0
- data/lib/ruby_llm/docker/pull_image.rb +127 -0
- data/lib/ruby_llm/docker/push_image.rb +153 -0
- data/lib/ruby_llm/docker/recreate_container.rb +151 -0
- data/lib/ruby_llm/docker/remove_container.rb +120 -0
- data/lib/ruby_llm/docker/remove_image.rb +142 -0
- data/lib/ruby_llm/docker/remove_network.rb +120 -0
- data/lib/ruby_llm/docker/remove_volume.rb +127 -0
- data/lib/ruby_llm/docker/run_container.rb +104 -0
- data/lib/ruby_llm/docker/start_container.rb +97 -0
- data/lib/ruby_llm/docker/stop_container.rb +109 -0
- data/lib/ruby_llm/docker/tag_image.rb +139 -0
- data/lib/ruby_llm/docker/version.rb +2 -2
- data/lib/ruby_llm/docker.rb +53 -3
- data/sig/ruby_llm/docker.rbs +1 -1
- metadata +90 -5
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyLLM
|
|
4
|
+
module Docker
|
|
5
|
+
# RubyLLM tool for creating Docker volumes.
|
|
6
|
+
#
|
|
7
|
+
# This tool provides the ability to create persistent Docker volumes for
|
|
8
|
+
# data storage that survives container lifecycle events. Volumes are the
|
|
9
|
+
# preferred mechanism for persisting data generated and used by Docker
|
|
10
|
+
# containers.
|
|
11
|
+
#
|
|
12
|
+
# == Features
|
|
13
|
+
#
|
|
14
|
+
# - Create named persistent volumes
|
|
15
|
+
# - Support for different volume drivers
|
|
16
|
+
# - Comprehensive error handling
|
|
17
|
+
# - Duplicate name detection
|
|
18
|
+
# - Flexible storage configuration
|
|
19
|
+
#
|
|
20
|
+
# == Volume Drivers
|
|
21
|
+
#
|
|
22
|
+
# Docker supports various volume drivers:
|
|
23
|
+
# - **local**: Default driver using host filesystem
|
|
24
|
+
# - **nfs**: Network File System for shared storage
|
|
25
|
+
# - **cifs**: Common Internet File System
|
|
26
|
+
# - **rexray**: External storage orchestration
|
|
27
|
+
# - **Custom**: Third-party volume drivers
|
|
28
|
+
#
|
|
29
|
+
# == Persistence Benefits
|
|
30
|
+
#
|
|
31
|
+
# Docker volumes provide several advantages:
|
|
32
|
+
# - **Data Persistence**: Survive container deletion and recreation
|
|
33
|
+
# - **Performance**: Better performance than bind mounts on Docker Desktop
|
|
34
|
+
# - **Portability**: Can be moved between containers and hosts
|
|
35
|
+
# - **Backup**: Easier to backup and restore than container filesystems
|
|
36
|
+
# - **Sharing**: Can be shared between multiple containers
|
|
37
|
+
# - **Management**: Managed by Docker daemon with proper lifecycle
|
|
38
|
+
#
|
|
39
|
+
# == Security Considerations
|
|
40
|
+
#
|
|
41
|
+
# Volume creation affects data security:
|
|
42
|
+
# - **Data Isolation**: Volumes provide isolation between containers
|
|
43
|
+
# - **Access Control**: Volume permissions affect data access
|
|
44
|
+
# - **Storage Location**: Local volumes stored on host filesystem
|
|
45
|
+
# - **Shared Access**: Multiple containers can access the same volume
|
|
46
|
+
#
|
|
47
|
+
# Security implications:
|
|
48
|
+
# - Volumes persist data beyond container lifecycle
|
|
49
|
+
# - Volume names may reveal application details
|
|
50
|
+
# - Shared volumes can leak data between containers
|
|
51
|
+
# - Storage driver choice affects security properties
|
|
52
|
+
#
|
|
53
|
+
# Best practices:
|
|
54
|
+
# - Use descriptive but not sensitive volume names
|
|
55
|
+
# - Implement proper volume access controls
|
|
56
|
+
# - Regular backup of critical volume data
|
|
57
|
+
# - Monitor volume usage and access patterns
|
|
58
|
+
# - Choose appropriate drivers for security requirements
|
|
59
|
+
#
|
|
60
|
+
# == Example Usage
|
|
61
|
+
#
|
|
62
|
+
# # Create basic local volume
|
|
63
|
+
# CreateVolume.call(
|
|
64
|
+
# server_context: context,
|
|
65
|
+
# name: "app-data"
|
|
66
|
+
# )
|
|
67
|
+
#
|
|
68
|
+
# # Create volume with specific driver
|
|
69
|
+
# CreateVolume.call(
|
|
70
|
+
# server_context: context,
|
|
71
|
+
# name: "shared-storage",
|
|
72
|
+
# driver: "nfs"
|
|
73
|
+
# )
|
|
74
|
+
#
|
|
75
|
+
# @see ListVolumes
|
|
76
|
+
# @see RemoveVolume
|
|
77
|
+
# @see Docker::Volume.create
|
|
78
|
+
# @since 0.1.0
|
|
79
|
+
class CreateVolume < RubyLLM::Tool
|
|
80
|
+
description 'Create a Docker volume'
|
|
81
|
+
|
|
82
|
+
param :name, type: :string, desc: 'Name of the volume'
|
|
83
|
+
param :driver, type: :string, desc: 'Driver to use (default: local)', required: false
|
|
84
|
+
|
|
85
|
+
# Create a new Docker volume for persistent data storage.
|
|
86
|
+
#
|
|
87
|
+
# This method creates a named Docker volume that can be used by containers
|
|
88
|
+
# for persistent data storage. The volume will survive container deletion
|
|
89
|
+
# and can be shared between multiple containers.
|
|
90
|
+
#
|
|
91
|
+
# @param name [String] name for the new volume
|
|
92
|
+
# @param server_context [Object] RubyLLM context (unused but required)
|
|
93
|
+
# @param driver [String] volume driver to use (default: "local")
|
|
94
|
+
#
|
|
95
|
+
# @return [RubyLLM::Tool::Response] volume creation results
|
|
96
|
+
#
|
|
97
|
+
# @raise [Docker::Error::ConflictError] if volume name already exists
|
|
98
|
+
# @raise [StandardError] for other volume creation failures
|
|
99
|
+
#
|
|
100
|
+
# @example Create application data volume
|
|
101
|
+
# response = CreateVolume.call(
|
|
102
|
+
# server_context: context,
|
|
103
|
+
# name: "webapp-data"
|
|
104
|
+
# )
|
|
105
|
+
#
|
|
106
|
+
# @example Create NFS volume
|
|
107
|
+
# response = tool.execute(
|
|
108
|
+
# name: "shared-files",
|
|
109
|
+
# driver: "nfs"
|
|
110
|
+
# )
|
|
111
|
+
#
|
|
112
|
+
# @see Docker::Volume.create
|
|
113
|
+
def execute(name:, driver: 'local')
|
|
114
|
+
options = {
|
|
115
|
+
'Name' => name,
|
|
116
|
+
'Driver' => driver
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
::Docker::Volume.create(name, options)
|
|
120
|
+
|
|
121
|
+
"Volume #{name} created successfully"
|
|
122
|
+
rescue ::Docker::Error::ConflictError
|
|
123
|
+
"Volume #{name} already exists"
|
|
124
|
+
rescue StandardError => e
|
|
125
|
+
"Error creating volume: #{e.message}"
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyLLM
|
|
4
|
+
module Docker
|
|
5
|
+
# RubyLLM tool for executing commands inside running Docker containers.
|
|
6
|
+
#
|
|
7
|
+
# This tool provides the ability to execute arbitrary commands inside running
|
|
8
|
+
# Docker containers, with full control over execution environment including
|
|
9
|
+
# working directory, user context, environment variables, and stdin input.
|
|
10
|
+
#
|
|
11
|
+
# == ⚠️ CRITICAL SECURITY WARNING ⚠️
|
|
12
|
+
#
|
|
13
|
+
# This tool is EXTREMELY DANGEROUS as it allows arbitrary command execution
|
|
14
|
+
# within Docker containers. This can be used to:
|
|
15
|
+
# - Execute malicious code inside containers
|
|
16
|
+
# - Access sensitive data within container filesystems
|
|
17
|
+
# - Escalate privileges if container is poorly configured
|
|
18
|
+
# - Perform lateral movement within containerized environments
|
|
19
|
+
# - Exfiltrate data from applications
|
|
20
|
+
#
|
|
21
|
+
# ONLY use this tool in trusted environments with proper security controls:
|
|
22
|
+
# - Ensure containers run with minimal privileges
|
|
23
|
+
# - Use read-only filesystems where possible
|
|
24
|
+
# - Implement proper network segmentation
|
|
25
|
+
# - Monitor and audit all command executions
|
|
26
|
+
# - Never expose this tool to untrusted clients
|
|
27
|
+
#
|
|
28
|
+
# == Features
|
|
29
|
+
#
|
|
30
|
+
# - Execute commands with custom working directory
|
|
31
|
+
# - Run commands as specific users
|
|
32
|
+
# - Set custom environment variables
|
|
33
|
+
# - Provide stdin input to commands
|
|
34
|
+
# - Configurable timeout protection
|
|
35
|
+
# - Comprehensive error handling
|
|
36
|
+
# - Separate stdout/stderr capture
|
|
37
|
+
#
|
|
38
|
+
# == Example Usage
|
|
39
|
+
#
|
|
40
|
+
# # Simple command execution
|
|
41
|
+
# ExecContainer.call(
|
|
42
|
+
# server_context: context,
|
|
43
|
+
# id: "my-container",
|
|
44
|
+
# cmd: "ls -la /app"
|
|
45
|
+
# )
|
|
46
|
+
#
|
|
47
|
+
# # Advanced execution with custom environment
|
|
48
|
+
# ExecContainer.call(
|
|
49
|
+
# server_context: context,
|
|
50
|
+
# id: "web-server",
|
|
51
|
+
# cmd: "python manage.py migrate",
|
|
52
|
+
# working_dir: "/app",
|
|
53
|
+
# user: "appuser",
|
|
54
|
+
# env: ["DJANGO_ENV=production", "DEBUG=false"],
|
|
55
|
+
# timeout: 120
|
|
56
|
+
# )
|
|
57
|
+
#
|
|
58
|
+
# @see Docker::Container#exec
|
|
59
|
+
# @since 0.1.0
|
|
60
|
+
class ExecContainer < RubyLLM::Tool
|
|
61
|
+
description 'Execute a command inside a running Docker container. ' \
|
|
62
|
+
'WARNING: This provides arbitrary command execution within the container. ' \
|
|
63
|
+
'Ensure proper security measures are in place.'
|
|
64
|
+
|
|
65
|
+
param :id, type: :string, desc: 'Container ID or name'
|
|
66
|
+
param :cmd, type: :string, desc: 'Command to execute (e.g., "ls -la /app" or "python script.py")'
|
|
67
|
+
param :working_dir, type: :string, desc: 'Working directory for the command (optional)', required: false
|
|
68
|
+
param :user, type: :string, desc: 'User to run the command as (optional, e.g., "1000" or "username")',
|
|
69
|
+
required: false
|
|
70
|
+
param :env, type: :string,
|
|
71
|
+
desc: 'Environment variables as comma-separated KEY=VALUE pairs ' \
|
|
72
|
+
'(optional, e.g., "VAR1=value1,VAR2=value2")',
|
|
73
|
+
required: false
|
|
74
|
+
param :stdin, type: :string, desc: 'Input to send to the command via stdin (optional)', required: false
|
|
75
|
+
param :timeout, type: :integer, desc: 'Timeout in seconds (optional, default: 60)', required: false
|
|
76
|
+
|
|
77
|
+
# Execute a command inside a running Docker container.
|
|
78
|
+
#
|
|
79
|
+
# This method provides comprehensive command execution capabilities within
|
|
80
|
+
# Docker containers, including advanced features like custom user context,
|
|
81
|
+
# environment variables, working directory, and stdin input.
|
|
82
|
+
#
|
|
83
|
+
# The command is parsed using shell-like syntax with support for quoted
|
|
84
|
+
# arguments. Output is captured separately for stdout and stderr, and
|
|
85
|
+
# the exit code is reported.
|
|
86
|
+
#
|
|
87
|
+
# @param id [String] container ID or name to execute command in
|
|
88
|
+
# @param cmd [String] command to execute (shell-parsed into arguments)
|
|
89
|
+
# @param server_context [Object] RubyLLM context (unused but required)
|
|
90
|
+
# @param working_dir [String, nil] working directory for command execution
|
|
91
|
+
# @param user [String, nil] user to run command as (username or UID)
|
|
92
|
+
# @param env [String, nil] environment variables as comma-separated KEY=VALUE pairs
|
|
93
|
+
# @param stdin [String, nil] input to send to command via stdin
|
|
94
|
+
# @param timeout [Integer] maximum execution time in seconds (default: 60)
|
|
95
|
+
#
|
|
96
|
+
# @return [RubyLLM::Tool::Response] execution results including stdout, stderr, and exit code
|
|
97
|
+
#
|
|
98
|
+
# @raise [Docker::Error::NotFoundError] if container doesn't exist
|
|
99
|
+
# @raise [Docker::Error::TimeoutError] if execution exceeds timeout
|
|
100
|
+
# @raise [StandardError] for other execution failures
|
|
101
|
+
#
|
|
102
|
+
# @example Basic command execution
|
|
103
|
+
# response = ExecContainer.call(
|
|
104
|
+
# server_context: context,
|
|
105
|
+
# id: "web-container",
|
|
106
|
+
# cmd: "nginx -t"
|
|
107
|
+
# )
|
|
108
|
+
#
|
|
109
|
+
# @example Advanced execution with environment
|
|
110
|
+
# response = tool.execute(
|
|
111
|
+
# id: "app-container",
|
|
112
|
+
# cmd: "bundle exec rails console",
|
|
113
|
+
# working_dir: "/app",
|
|
114
|
+
# user: "rails",
|
|
115
|
+
# env: ["RAILS_ENV=production"],
|
|
116
|
+
# timeout: 300
|
|
117
|
+
# )
|
|
118
|
+
#
|
|
119
|
+
# @see Docker::Container#exec
|
|
120
|
+
def execute(id:, cmd:, working_dir: nil, user: nil,
|
|
121
|
+
env: nil, stdin: nil, timeout: 60)
|
|
122
|
+
container = ::Docker::Container.get(id)
|
|
123
|
+
|
|
124
|
+
# Parse command string into array
|
|
125
|
+
# Simple shell-like parsing: split on spaces but respect quoted strings
|
|
126
|
+
cmd_array = Shellwords.split(cmd)
|
|
127
|
+
|
|
128
|
+
# Parse environment variables string into array if provided
|
|
129
|
+
env_array = nil
|
|
130
|
+
env_array = env.split(',').map(&:strip).select { |e| e.include?('=') } if env && !env.empty?
|
|
131
|
+
|
|
132
|
+
# Build exec options
|
|
133
|
+
exec_options = {
|
|
134
|
+
'Cmd' => cmd_array,
|
|
135
|
+
'AttachStdout' => true,
|
|
136
|
+
'AttachStderr' => true
|
|
137
|
+
}
|
|
138
|
+
exec_options['WorkingDir'] = working_dir if working_dir
|
|
139
|
+
exec_options['User'] = user if user
|
|
140
|
+
exec_options['Env'] = env_array if env_array
|
|
141
|
+
exec_options['AttachStdin'] = true if stdin
|
|
142
|
+
|
|
143
|
+
# Execute the command
|
|
144
|
+
stdout_data = []
|
|
145
|
+
stderr_data = []
|
|
146
|
+
exit_code = nil
|
|
147
|
+
|
|
148
|
+
begin
|
|
149
|
+
# Use container.exec which returns [stdout, stderr, exit_code]
|
|
150
|
+
result = if stdin
|
|
151
|
+
container.exec(cmd_array, stdin: StringIO.new(stdin), wait: timeout)
|
|
152
|
+
else
|
|
153
|
+
container.exec(cmd_array, wait: timeout)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
stdout_data = result[0]
|
|
157
|
+
stderr_data = result[1]
|
|
158
|
+
exit_code = result[2]
|
|
159
|
+
rescue ::Docker::Error::TimeoutError
|
|
160
|
+
return "Command execution timed out after #{timeout} seconds"
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# Format response
|
|
164
|
+
response_text = "Command executed in container #{id}\n"
|
|
165
|
+
response_text += "Exit code: #{exit_code}\n\n"
|
|
166
|
+
|
|
167
|
+
if stdout_data && !stdout_data.empty?
|
|
168
|
+
stdout_str = stdout_data.join
|
|
169
|
+
response_text += "STDOUT:\n#{stdout_str}\n" unless stdout_str.strip.empty?
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
if stderr_data && !stderr_data.empty?
|
|
173
|
+
stderr_str = stderr_data.join
|
|
174
|
+
response_text += "\nSTDERR:\n#{stderr_str}\n" unless stderr_str.strip.empty?
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
response_text.strip
|
|
178
|
+
rescue ::Docker::Error::NotFoundError
|
|
179
|
+
"Container #{id} not found"
|
|
180
|
+
rescue StandardError => e
|
|
181
|
+
"Error executing command: #{e.message}"
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyLLM
|
|
4
|
+
module Docker
|
|
5
|
+
# RubyLLM tool for retrieving Docker container logs.
|
|
6
|
+
#
|
|
7
|
+
# This tool provides access to container logs with flexible filtering and
|
|
8
|
+
# formatting options. It can retrieve both stdout and stderr logs with
|
|
9
|
+
# optional timestamps and tail functionality for recent entries.
|
|
10
|
+
#
|
|
11
|
+
# == Features
|
|
12
|
+
#
|
|
13
|
+
# - Retrieve stdout and/or stderr logs
|
|
14
|
+
# - Optional timestamp inclusion
|
|
15
|
+
# - Tail functionality for recent logs
|
|
16
|
+
# - Flexible log stream selection
|
|
17
|
+
# - Comprehensive error handling
|
|
18
|
+
# - Works with any container state
|
|
19
|
+
#
|
|
20
|
+
# == Log Sources
|
|
21
|
+
#
|
|
22
|
+
# Docker containers can generate logs from multiple sources:
|
|
23
|
+
# - **stdout**: Standard output from container processes
|
|
24
|
+
# - **stderr**: Standard error from container processes
|
|
25
|
+
# - **timestamps**: Docker-generated timestamps for each log line
|
|
26
|
+
#
|
|
27
|
+
# == Security Considerations
|
|
28
|
+
#
|
|
29
|
+
# Container logs may contain sensitive information:
|
|
30
|
+
# - Application secrets and API keys
|
|
31
|
+
# - User data and personal information
|
|
32
|
+
# - Internal system information
|
|
33
|
+
# - Database connection strings
|
|
34
|
+
# - Error messages with stack traces
|
|
35
|
+
#
|
|
36
|
+
# Security recommendations:
|
|
37
|
+
# - Review log content before sharing
|
|
38
|
+
# - Limit access to container logs
|
|
39
|
+
# - Sanitize logs in production environments
|
|
40
|
+
# - Use log rotation to manage log size
|
|
41
|
+
# - Be cautious with log forwarding
|
|
42
|
+
#
|
|
43
|
+
# == Example Usage
|
|
44
|
+
#
|
|
45
|
+
# # Get all logs
|
|
46
|
+
# FetchContainerLogs.call(
|
|
47
|
+
# server_context: context,
|
|
48
|
+
# id: "web-server"
|
|
49
|
+
# )
|
|
50
|
+
#
|
|
51
|
+
# # Get recent logs with timestamps
|
|
52
|
+
# FetchContainerLogs.call(
|
|
53
|
+
# server_context: context,
|
|
54
|
+
# id: "app-container",
|
|
55
|
+
# tail: 100,
|
|
56
|
+
# timestamps: true
|
|
57
|
+
# )
|
|
58
|
+
#
|
|
59
|
+
# # Get only error logs
|
|
60
|
+
# FetchContainerLogs.call(
|
|
61
|
+
# server_context: context,
|
|
62
|
+
# id: "database",
|
|
63
|
+
# stdout: false,
|
|
64
|
+
# stderr: true
|
|
65
|
+
# )
|
|
66
|
+
#
|
|
67
|
+
# @see ExecContainer
|
|
68
|
+
# @see Docker::Container#logs
|
|
69
|
+
# @since 0.1.0
|
|
70
|
+
class FetchContainerLogs < RubyLLM::Tool
|
|
71
|
+
description 'Fetch Docker container logs'
|
|
72
|
+
|
|
73
|
+
param :id, type: :string, desc: 'Container ID or name'
|
|
74
|
+
param :stdout, type: :boolean, desc: 'Include stdout (default: true)', required: false
|
|
75
|
+
param :stderr, type: :boolean, desc: 'Include stderr (default: true)', required: false
|
|
76
|
+
param :tail, type: :integer, desc: 'Number of lines to show from the end of logs (default: all)',
|
|
77
|
+
required: false
|
|
78
|
+
param :timestamps, type: :boolean, desc: 'Show timestamps (default: false)', required: false
|
|
79
|
+
|
|
80
|
+
# Retrieve logs from a Docker container.
|
|
81
|
+
#
|
|
82
|
+
# This method fetches logs from the specified container with configurable
|
|
83
|
+
# options for log sources (stdout/stderr), formatting (timestamps), and
|
|
84
|
+
# quantity (tail). The logs are returned as a text response.
|
|
85
|
+
#
|
|
86
|
+
# @param id [String] container ID (full or short) or container name
|
|
87
|
+
# @param server_context [Object] RubyLLM context (unused but required)
|
|
88
|
+
# @param stdout [Boolean] whether to include stdout logs (default: true)
|
|
89
|
+
# @param stderr [Boolean] whether to include stderr logs (default: true)
|
|
90
|
+
# @param tail [Integer, nil] number of recent lines to return (nil for all)
|
|
91
|
+
# @param timestamps [Boolean] whether to include timestamps (default: false)
|
|
92
|
+
#
|
|
93
|
+
# @return [RubyLLM::Tool::Response] container logs as text
|
|
94
|
+
#
|
|
95
|
+
# @raise [Docker::Error::NotFoundError] if container doesn't exist
|
|
96
|
+
# @raise [StandardError] for other log retrieval failures
|
|
97
|
+
#
|
|
98
|
+
# @example Get all logs
|
|
99
|
+
# response = FetchContainerLogs.call(
|
|
100
|
+
# server_context: context,
|
|
101
|
+
# id: "nginx-server"
|
|
102
|
+
# )
|
|
103
|
+
#
|
|
104
|
+
# @example Get recent error logs with timestamps
|
|
105
|
+
# response = tool.execute(
|
|
106
|
+
# id: "app-container",
|
|
107
|
+
# stdout: false,
|
|
108
|
+
# stderr: true,
|
|
109
|
+
# tail: 50,
|
|
110
|
+
# timestamps: true
|
|
111
|
+
# )
|
|
112
|
+
#
|
|
113
|
+
# @see Docker::Container#logs
|
|
114
|
+
def execute(id:, stdout: true, stderr: true, tail: nil, timestamps: false)
|
|
115
|
+
container = ::Docker::Container.get(id)
|
|
116
|
+
|
|
117
|
+
options = {
|
|
118
|
+
stdout: stdout,
|
|
119
|
+
stderr: stderr,
|
|
120
|
+
timestamps: timestamps
|
|
121
|
+
}
|
|
122
|
+
options[:tail] = tail if tail
|
|
123
|
+
|
|
124
|
+
container.logs(options)
|
|
125
|
+
rescue ::Docker::Error::NotFoundError
|
|
126
|
+
"Container #{id} not found"
|
|
127
|
+
rescue StandardError => e
|
|
128
|
+
"Error fetching logs: #{e.message}"
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyLLM
|
|
4
|
+
module Docker
|
|
5
|
+
# RubyLLM tool for listing Docker containers.
|
|
6
|
+
#
|
|
7
|
+
# This tool provides functionality to list all Docker containers on the system,
|
|
8
|
+
# including both running and stopped containers. It returns detailed information
|
|
9
|
+
# about each container including names, images, status, ports, and other metadata.
|
|
10
|
+
#
|
|
11
|
+
# == Security Notes
|
|
12
|
+
#
|
|
13
|
+
# This is a read-only operation that provides system information about containers.
|
|
14
|
+
# While generally safe, it may reveal information about the Docker environment
|
|
15
|
+
# that could be useful for reconnaissance.
|
|
16
|
+
#
|
|
17
|
+
# == Example Usage
|
|
18
|
+
#
|
|
19
|
+
# # List all containers (default behavior)
|
|
20
|
+
# ListContainers.call(server_context: context)
|
|
21
|
+
#
|
|
22
|
+
# # Explicitly request all containers
|
|
23
|
+
# ListContainers.call(server_context: context, all: true)
|
|
24
|
+
#
|
|
25
|
+
# @see Docker::Container.all
|
|
26
|
+
# @since 0.1.0
|
|
27
|
+
class ListContainers < RubyLLM::Tool
|
|
28
|
+
description 'List Docker containers'
|
|
29
|
+
|
|
30
|
+
param :all, type: :boolean, desc: 'Show all containers (default shows all containers including stopped ones)',
|
|
31
|
+
required: false
|
|
32
|
+
|
|
33
|
+
# List all Docker containers with detailed information.
|
|
34
|
+
#
|
|
35
|
+
# Retrieves information about all containers on the system, including:
|
|
36
|
+
# - Container names and IDs
|
|
37
|
+
# - Image information
|
|
38
|
+
# - Current state (running, stopped, etc.)
|
|
39
|
+
# - Port mappings
|
|
40
|
+
# - Network configuration
|
|
41
|
+
# - Volume mounts
|
|
42
|
+
# - Creation and status timestamps
|
|
43
|
+
#
|
|
44
|
+
# @param server_context [Object] the RubyLLM context (unused but required)
|
|
45
|
+
# @param all [Boolean] whether to show all containers (default: true)
|
|
46
|
+
# @return [RubyLLM::Tool::Response] response containing container information
|
|
47
|
+
#
|
|
48
|
+
# @example List all containers
|
|
49
|
+
# response = ListContainers.call(server_context: context)
|
|
50
|
+
# # Returns detailed info for all containers
|
|
51
|
+
#
|
|
52
|
+
# @see Docker::Container.all
|
|
53
|
+
def execute(all: true)
|
|
54
|
+
require 'docker'
|
|
55
|
+
::Docker::Container.all(all: all).map(&:info).to_s
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyLLM
|
|
4
|
+
module Docker
|
|
5
|
+
# RubyLLM tool for listing Docker images.
|
|
6
|
+
#
|
|
7
|
+
# This tool provides functionality to list all Docker images available on
|
|
8
|
+
# the local system. It returns comprehensive information about each image
|
|
9
|
+
# including IDs, tags, sizes, creation dates, and other metadata.
|
|
10
|
+
#
|
|
11
|
+
# == Features
|
|
12
|
+
#
|
|
13
|
+
# - List all local Docker images
|
|
14
|
+
# - Comprehensive image metadata
|
|
15
|
+
# - No configuration required
|
|
16
|
+
# - Read-only operation
|
|
17
|
+
# - Includes both tagged and untagged images
|
|
18
|
+
#
|
|
19
|
+
# == Image Information Included
|
|
20
|
+
#
|
|
21
|
+
# The response typically includes:
|
|
22
|
+
# - **Image ID**: Unique identifier for the image
|
|
23
|
+
# - **Repository Tags**: All tags associated with the image
|
|
24
|
+
# - **Size**: Virtual and actual size of the image
|
|
25
|
+
# - **Created**: Timestamp when image was created
|
|
26
|
+
# - **Parent ID**: Base image information
|
|
27
|
+
# - **RepoDigests**: Content-addressable identifiers
|
|
28
|
+
#
|
|
29
|
+
# == Security Considerations
|
|
30
|
+
#
|
|
31
|
+
# This is a read-only operation that reveals system information:
|
|
32
|
+
# - Exposes available images and versions
|
|
33
|
+
# - May reveal internal application details
|
|
34
|
+
# - Shows image sources and repositories
|
|
35
|
+
# - Could aid in reconnaissance activities
|
|
36
|
+
#
|
|
37
|
+
# While generally safe, consider access control:
|
|
38
|
+
# - Limit exposure of image inventory
|
|
39
|
+
# - Be cautious with sensitive image names
|
|
40
|
+
# - Monitor for unauthorized image access attempts
|
|
41
|
+
#
|
|
42
|
+
# == Example Usage
|
|
43
|
+
#
|
|
44
|
+
# # List all images
|
|
45
|
+
# ListImages.call(server_context: context)
|
|
46
|
+
#
|
|
47
|
+
# @example Usage in container management
|
|
48
|
+
# # Get available images before container creation
|
|
49
|
+
# images_response = ListImages.call(server_context: context)
|
|
50
|
+
# # Use image information to select appropriate base images
|
|
51
|
+
#
|
|
52
|
+
# @see PullImage
|
|
53
|
+
# @see BuildImage
|
|
54
|
+
# @see Docker::Image.all
|
|
55
|
+
# @since 0.1.0
|
|
56
|
+
class ListImages < RubyLLM::Tool
|
|
57
|
+
description 'List Docker images'
|
|
58
|
+
|
|
59
|
+
# List all Docker images available on the local system.
|
|
60
|
+
#
|
|
61
|
+
# This method retrieves information about all Docker images stored
|
|
62
|
+
# locally, including both tagged and untagged images. The information
|
|
63
|
+
# includes comprehensive metadata for each image.
|
|
64
|
+
#
|
|
65
|
+
# @param args [Array] variable arguments (unused but accepted for compatibility)
|
|
66
|
+
#
|
|
67
|
+
# @return [RubyLLM::Tool::Response] comprehensive image information
|
|
68
|
+
#
|
|
69
|
+
# @example List all local images
|
|
70
|
+
# response = ListImages.call
|
|
71
|
+
# # Returns detailed info for all local Docker images
|
|
72
|
+
#
|
|
73
|
+
# @see Docker::Image.all
|
|
74
|
+
def execute
|
|
75
|
+
::Docker::Image.all.map(&:info).to_s
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyLLM
|
|
4
|
+
module Docker
|
|
5
|
+
# RubyLLM tool for listing Docker networks.
|
|
6
|
+
#
|
|
7
|
+
# This tool provides functionality to list all Docker networks available on
|
|
8
|
+
# the system, including built-in networks (bridge, host, none) and custom
|
|
9
|
+
# user-defined networks. It returns comprehensive information about network
|
|
10
|
+
# configuration, drivers, and connected containers.
|
|
11
|
+
#
|
|
12
|
+
# == Features
|
|
13
|
+
#
|
|
14
|
+
# - List all Docker networks on the system
|
|
15
|
+
# - Comprehensive network metadata
|
|
16
|
+
# - No configuration required
|
|
17
|
+
# - Read-only operation
|
|
18
|
+
# - Includes built-in and custom networks
|
|
19
|
+
#
|
|
20
|
+
# == Network Information Included
|
|
21
|
+
#
|
|
22
|
+
# The response typically includes:
|
|
23
|
+
# - **Network ID**: Unique identifier for the network
|
|
24
|
+
# - **Name**: Human-readable network name
|
|
25
|
+
# - **Driver**: Network driver (bridge, host, overlay, etc.)
|
|
26
|
+
# - **Scope**: Network scope (local, global, swarm)
|
|
27
|
+
# - **IPAM**: IP Address Management configuration
|
|
28
|
+
# - **Connected Containers**: Containers attached to the network
|
|
29
|
+
# - **Options**: Driver-specific configuration options
|
|
30
|
+
#
|
|
31
|
+
# == Security Considerations
|
|
32
|
+
#
|
|
33
|
+
# This is a read-only operation that reveals network topology:
|
|
34
|
+
# - Exposes network architecture and segmentation
|
|
35
|
+
# - Shows container connectivity patterns
|
|
36
|
+
# - May reveal internal network design
|
|
37
|
+
# - Could aid in network reconnaissance
|
|
38
|
+
#
|
|
39
|
+
# While generally safe, consider access control:
|
|
40
|
+
# - Limit exposure of network topology information
|
|
41
|
+
# - Be cautious with sensitive network names
|
|
42
|
+
# - Monitor for unauthorized network discovery
|
|
43
|
+
# - Consider network isolation requirements
|
|
44
|
+
#
|
|
45
|
+
# == Example Usage
|
|
46
|
+
#
|
|
47
|
+
# # List all networks
|
|
48
|
+
# ListNetworks.call(server_context: context)
|
|
49
|
+
#
|
|
50
|
+
# @example Usage in network management
|
|
51
|
+
# # Get available networks before container creation
|
|
52
|
+
# networks_response = ListNetworks.call(server_context: context)
|
|
53
|
+
# # Use network information to select appropriate networks
|
|
54
|
+
#
|
|
55
|
+
# @see CreateNetwork
|
|
56
|
+
# @see RemoveNetwork
|
|
57
|
+
# @see Docker::Network.all
|
|
58
|
+
# @since 0.1.0
|
|
59
|
+
class ListNetworks < RubyLLM::Tool
|
|
60
|
+
description 'List Docker networks'
|
|
61
|
+
|
|
62
|
+
# List all Docker networks available on the system.
|
|
63
|
+
#
|
|
64
|
+
# This method retrieves information about all Docker networks, including
|
|
65
|
+
# both system-created networks (bridge, host, none) and user-defined
|
|
66
|
+
# custom networks. The information includes comprehensive metadata for
|
|
67
|
+
# each network.
|
|
68
|
+
#
|
|
69
|
+
# @return [String] comprehensive network information
|
|
70
|
+
#
|
|
71
|
+
# @example List all networks
|
|
72
|
+
# response = tool.execute
|
|
73
|
+
# # Returns detailed info for all Docker networks
|
|
74
|
+
#
|
|
75
|
+
# @see Docker::Network.all
|
|
76
|
+
def execute
|
|
77
|
+
::Docker::Network.all.map(&:info).to_s
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|