### Basic Setup for RubyLLM Docker Tools Source: https://github.com/afstanton/ruby_llm-docker/blob/main/README.md Demonstrates how to initialize a RubyLLM chat instance and add Docker management tools. This setup allows an AI to interact with Docker functionalities. Ensure you have the `ruby_llm` gem and Docker installed. ```ruby require 'ruby_llm/docker' # Create a new chat instance chat = RubyLLM::Chat.new( api_key: 'your-openai-api-key', model: 'gpt-4' ) # Add all Docker tools to the chat RubyLLM::Docker.add_all_tools_to_chat(chat) # Or add individual tools chat.tools << RubyLLM::Docker::ListContainers.new chat.tools << RubyLLM::Docker::RunContainer.new # ... etc ``` -------------------------------- ### Bash: Local Development Setup for Ruby LLM Docker Source: https://github.com/afstanton/ruby_llm-docker/blob/main/README.md This snippet details the bash commands for cloning the repository, navigating into the project directory, installing project dependencies, and starting an interactive console for local development. ```bash # Clone the repository git clone https://github.com/afstanton/ruby_llm-docker.git cd ruby_llm-docker # Install dependencies bin/setup # Start development console bin/console ``` -------------------------------- ### Bash: Ruby Project Setup and Testing Source: https://github.com/afstanton/ruby_llm-docker/blob/main/README.md This snippet outlines the bash commands required for setting up and testing the ruby_llm-docker project. It covers installing dependencies with Bundler, running the test suite using Rake, and generating code coverage reports. ```bash # Install dependencies bundle install # Run the test suite bundle exec rake spec # Run tests with coverage bundle exec rake spec COVERAGE=true ``` -------------------------------- ### Ruby: Set Up Development Environment with Docker Source: https://github.com/afstanton/ruby_llm-docker/blob/main/README.md This snippet demonstrates how to use the chat interface to pull a Docker image, create a named container with exposed ports, and mount local directories. It also shows how to execute commands within the container to install dependencies and start an application. ```ruby # Ask the AI to set up a development environment response = chat.ask("Pull the node:18-alpine image and create a development container named 'dev-env' with port 3000 exposed and my current directory mounted as /app") # Install dependencies and start the application response = chat.ask("Run 'npm install' in the dev-env container") response = chat.ask("Start the application with 'npm start' in the dev-env container") ``` -------------------------------- ### Run Docker Container with RubyLLM Source: https://context7.com/afstanton/ruby_llm-docker/llms.txt This Ruby snippet illustrates how to create and start a Docker container from an image with custom configurations using the RubyLLM Docker tools. It demonstrates running a basic Nginx container and a Node.js container with environment variables and volume mounts. ```ruby require 'ruby_llm/docker' RubyLLM.configure do |config| config.openai_api_key = ENV['OPENAI_API_KEY'] end chat = RubyLLM.chat(model: 'gpt-4') chat.with_tool(RubyLLM::Docker::RunContainer) # Create and start an nginx web server response = chat.ask( "Create a new nginx container named 'web-server' and expose port 8080 to host port 80" ) puts response.content # Expected output: "Container started successfully. ID: abc123..., Name: web-server" # With environment variables and custom command response = chat.ask( "Run a Node.js container named 'app' with NODE_ENV=production, " \ "mount /local/app to /usr/src/app, expose port 3000, and run 'npm start'" ) puts response.content ``` -------------------------------- ### Running Interactive Command Line Tool (Ruby) Source: https://github.com/afstanton/ruby_llm-docker/blob/main/README.md Provides instructions to run an interactive command-line interface for Docker management using the RubyLLM Docker gem. This requires setting the OpenAI API key and can be run via a direct Ruby command or an example script. Ensure the gem is installed and Docker is running. ```bash # Set your OpenAI API key export OPENAI_API_KEY='your-key-here' # Run the interactive Docker chat ruby -r 'ruby_llm/docker' -e " require_relative 'examples/docker_chat.rb' DockerChat.new.start " # Or use the included example script: ruby examples/docker_chat.rb ``` -------------------------------- ### Example Usage of RubyLLM Docker Tools Source: https://github.com/afstanton/ruby_llm-docker/blob/main/README.md Illustrates natural language commands that can be sent to a configured RubyLLM chat instance to manage Docker resources. These examples cover listing containers, creating and running new containers, executing commands, copying files, and fetching logs. Assumes the chat object is already set up with Docker tools. ```ruby # List all containers response = chat.ask("How many containers are currently running?") # Create and run a new container response = chat.ask("Create a new nginx container named 'my-web-server' and expose port 8080") # Execute commands in a container response = chat.ask("Check the nginx version in the my-web-server container") # Copy files to a container response = chat.ask("Copy my local config.txt file to /etc/nginx/ in the web server container") # View container logs response = chat.ask("Show me the logs for the my-web-server container") ``` -------------------------------- ### Bash: Building and Installing Local Ruby Gem Source: https://github.com/afstanton/ruby_llm-docker/blob/main/README.md This snippet shows the bash commands for building a local Ruby gem from the project and then installing it onto the local machine. This is useful for testing changes before publishing. ```bash # Build the gem locally bundle exec rake build # Install locally built gem bundle exec rake install ``` -------------------------------- ### Gem Installation for ruby_llm-docker Source: https://github.com/afstanton/ruby_llm-docker/blob/main/README.md Provides the command to install the `ruby_llm-docker` gem directly using the `gem` command, suitable for environments where Bundler is not used. This installs the gem globally or to the current Ruby environment. Ensure you have RubyGems installed. ```bash gem install ruby_llm-docker ``` -------------------------------- ### Create Docker Network using Ruby LLM Source: https://context7.com/afstanton/ruby_llm-docker/llms.txt This code example shows how to create Docker networks, including basic bridge networks for local communication and overlay networks for distributed environments, using the Ruby LLM library. An OpenAI API key is necessary for this operation. ```ruby require 'ruby_llm/docker' RubyLLM.configure do |config| config.openai_api_key = ENV['OPENAI_API_KEY'] end chat = RubyLLM.chat(model: 'gpt-4') chat.with_tool(RubyLLM::Docker::CreateNetwork) # Create basic bridge network response = chat.ask("Create a Docker network named 'app-network'") puts response.content # Expected output: "Network app-network created successfully. ID: 1a2b3c4d..." # Create overlay network for swarm response = chat.ask( "Create an overlay network named 'swarm-network' for multi-host communication" ) puts response.content ``` -------------------------------- ### Bundler Installation for ruby_llm-docker Source: https://github.com/afstanton/ruby_llm-docker/blob/main/README.md Shows the command to add the `ruby_llm-docker` gem to your application's Gemfile using Bundler. This is the recommended way to manage gem dependencies in a Ruby project. Ensure you have Bundler installed. ```bash bundle add ruby_llm-docker ``` -------------------------------- ### Copy Files to Docker Container with RubyLLM Source: https://context7.com/afstanton/ruby_llm-docker/llms.txt This Ruby snippet shows how to copy files and directories from the host filesystem into running Docker containers using the RubyLLM Docker tools. Examples include copying a single configuration file and an entire directory with ownership changes. ```ruby require 'ruby_llm/docker' RubyLLM.configure do |config| config.openai_api_key = ENV['OPENAI_API_KEY'] end chat = RubyLLM.chat(model: 'gpt-4') chat.with_tool(RubyLLM::Docker::CopyToContainer) # Copy single file response = chat.ask( "Copy my local nginx.conf file to /etc/nginx/nginx.conf in the web-server container" ) puts response.content # Expected output: "Successfully copied file from nginx.conf to web-server:/etc/nginx/" # Copy directory with ownership change response = chat.ask( "Copy the entire src directory to /app in the app-container and set owner to www-data:www-data" ) puts response.content ``` -------------------------------- ### Bash: Testing Ruby LLM Docker with API Keys Source: https://github.com/afstanton/ruby_llm-docker/blob/main/README.md This snippet provides bash commands for testing the Ruby LLM Docker project's interactive chat functionality. It requires setting the OPENAI_API_KEY environment variable before running the example script. ```bash # Test the interactive chat tool export OPENAI_API_KEY='your-key-here' ruby examples/docker_chat.rb # Test tool loading without API calls ruby examples/test_chat.rb ``` -------------------------------- ### Create Docker Volume using Ruby LLM Source: https://context7.com/afstanton/ruby_llm-docker/llms.txt This Ruby snippet illustrates the creation of Docker volumes for persistent data storage. It covers creating local volumes for applications like databases and volumes utilizing drivers such as NFS for network-attached storage. The `ruby_llm/docker` library and an OpenAI API key are prerequisites. ```ruby require 'ruby_llm/docker' RubyLLM.configure do |config| config.openai_api_key = ENV['OPENAI_API_KEY'] end chat = RubyLLM.chat(model: 'gpt-4') chat.with_tool(RubyLLM::Docker::CreateVolume) # Create local volume response = chat.ask("Create a Docker volume named 'postgres-data' for database persistence") puts response.content # Expected output: "Volume postgres-data created successfully" # Create volume with NFS driver response = chat.ask( "Create a volume named 'shared-storage' using the NFS driver for network storage" ) puts response.content ``` -------------------------------- ### List Docker Containers with RubyLLM Source: https://context7.com/afstanton/ruby_llm-docker/llms.txt This Ruby code snippet shows how to retrieve comprehensive information about all Docker containers, including running and stopped ones, using the RubyLLM Docker tools. It requires configuring the API key and then using the `ListContainers` tool within a chat session. ```ruby require 'ruby_llm/docker' RubyLLM.configure do |config| config.openai_api_key = ENV['OPENAI_API_KEY'] end chat = RubyLLM.chat(model: 'gpt-4') chat.with_tool(RubyLLM::Docker::ListContainers) response = chat.ask('Show me all Docker containers with their status') puts response.content # Expected output: Detailed list of containers with names, IDs, status, ports, and resource usage ``` -------------------------------- ### Add All Docker Tools to RubyLLM Chat Source: https://context7.com/afstanton/ruby_llm-docker/llms.txt This snippet demonstrates how to add all 22 Docker management tools to a RubyLLM chat instance in a single operation. It requires the 'ruby_llm/docker' gem and OpenAI API key configuration. The output shows the response from asking a question after tools are added. ```ruby require 'ruby_llm/docker' # Configure RubyLLM with OpenAI RubyLLM.configure do |config| config.openai_api_key = ENV['OPENAI_API_KEY'] end # Create chat and add all Docker tools chat = RubyLLM::Chat.new( api_key: ENV['OPENAI_API_KEY'], model: 'gpt-4' ) RubyLLM::Docker.add_all_tools_to_chat(chat) # Now chat has access to all Docker operations response = chat.ask("How many containers are running?") puts response.content # Expected output: "There are 3 containers currently running on this system." ``` -------------------------------- ### List Docker Images with RubyLLM Source: https://context7.com/afstanton/ruby_llm-docker/llms.txt This Ruby code snippet demonstrates how to retrieve comprehensive information about all locally stored Docker images using the RubyLLM Docker tools. It requires API key configuration and the use of the `ListImages` tool within a chat session. ```ruby require 'ruby_llm/docker' RubyLLM.configure do |config| config.openai_api_key = ENV['OPENAI_API_KEY'] end chat = RubyLLM.chat(model: 'gpt-4') chat.with_tool(RubyLLM::Docker::ListImages) response = chat.ask('What Docker images do I have locally?') puts response.content # Expected output: List of images with repository tags, sizes, and creation dates ``` -------------------------------- ### Ruby: Managing Files in Docker Containers Source: https://github.com/afstanton/ruby_llm-docker/blob/main/README.md This snippet illustrates using the chat interface to copy files between the local system and Docker containers. It covers copying individual files, such as configuration files, and entire directories into specified locations within the container. ```ruby # Copy files to containers using natural language response = chat.ask("Copy my local nginx.conf file to /etc/nginx/ in the web-server container") response = chat.ask("Copy the entire src directory to /app/ in the app-container") ``` -------------------------------- ### Bash: Verify Docker Daemon and Permissions Source: https://github.com/afstanton/ruby_llm-docker/blob/main/README.md This snippet provides essential bash commands for troubleshooting Docker. It includes checking if the Docker daemon is running using `docker info` and verifying user permissions to interact with the Docker daemon using `docker ps`. ```bash # Check if Docker daemon is running docker info # Verify Docker permissions docker ps ``` -------------------------------- ### Interactive Docker CLI Chat with Ruby LLM Source: https://context7.com/afstanton/ruby_llm-docker/llms.txt This Ruby script creates an interactive command-line interface (CLI) that integrates all available Docker tools provided by the Ruby LLM library. Users can converse with the CLI to manage Docker resources like images, containers, networks, and volumes. It requires the `ruby_llm/docker` gem and the `OPENAI_API_KEY` environment variable to be set. ```ruby #!/usr/bin/env ruby require 'ruby_llm/docker' class DockerChat def initialize check_api_key setup_chat end def start show_welcome main_loop end private def check_api_key unless ENV['OPENAI_API_KEY'] puts 'Error: Please set OPENAI_API_KEY environment variable' exit 1 end end def setup_chat RubyLLM.configure do |config| config.openai_api_key = ENV['OPENAI_API_KEY'] end @chat = RubyLLM.chat(model: 'gpt-4') .on_tool_call { |tool| puts "šŸ”§ Calling: #{tool.name}" } .on_tool_result { |result| puts "āœ… Result: #{result}" } RubyLLM::Docker.add_all_tools_to_chat(@chat) puts "āœ… Loaded #{RubyLLM::Docker.all_tools.size} Docker tools" end def show_welcome puts "\n🐳 Welcome to Docker Chat!" puts "Ask questions about Docker containers, images, networks, and volumes." puts "Type /exit to quit\n\n" end def main_loop loop do print "🐳 > " input = gets.chomp break if input == '/exit' response = @chat.ask(input) puts "\n#{response.content}\n\n" rescue StandardError => e puts "Error: #{e.message}" end end end DockerChat.new.start if __FILE__ == $PROGRAM_NAME # Usage: # export OPENAI_API_KEY='your-key-here' # ruby docker_chat.rb # # Example interaction: # 🐳 > How many containers are running? # šŸ”§ Calling: list_containers # āœ… Result: [{"Id"=>"abc123", "Names"=>["/web"], "State"=>"running"}, ...] # There are 3 containers currently running on this system. ``` -------------------------------- ### Execute Command in Docker Container with RubyLLM Source: https://context7.com/afstanton/ruby_llm-docker/llms.txt This Ruby code demonstrates executing arbitrary commands inside running Docker containers using RubyLLM's Docker tools. It covers executing basic commands like checking versions and more complex commands with environment variables and specific working directories. ```ruby require 'ruby_llm/docker' RubyLLM.configure do |config| config.openai_api_key = ENV['OPENAI_API_KEY'] end chat = RubyLLM.chat(model: 'gpt-4') chat.with_tool(RubyLLM::Docker::ExecContainer) # Execute basic command response = chat.ask("Check the nginx version in the web-server container") puts response.content # Expected output: # Command executed in container web-server # Exit code: 0 # STDOUT: # nginx version: nginx/1.21.6 # Execute with environment variables and working directory response = chat.ask( "In the app container, run 'bundle exec rake db:migrate' " \ "with RAILS_ENV=production from /app directory" ) puts response.content ``` -------------------------------- ### Pull Docker Image using Ruby LLM Source: https://context7.com/afstanton/ruby_llm-docker/llms.txt This snippet demonstrates how to pull Docker images, both the latest version and specific versions, from a registry using the Ruby LLM Docker tool. It requires the `ruby_llm/docker` library and an OpenAI API key. ```ruby require 'ruby_llm/docker' RubyLLM.configure do |config| config.openai_api_key = ENV['OPENAI_API_KEY'] end chat = RubyLLM.chat(model: 'gpt-4') chat.with_tool(RubyLLM::Docker::PullImage) # Pull latest version response = chat.ask("Pull the latest nginx image") puts response.content # Expected output: "Image nginx:latest pulled successfully. ID: sha256:abc123..." # Pull specific version response = chat.ask("Pull PostgreSQL version 13.8") puts response.content # Expected output: "Image postgres:13.8 pulled successfully. ID: sha256:def456..." ``` -------------------------------- ### Ruby: Debugging Docker Containers with Chat Source: https://github.com/afstanton/ruby_llm-docker/blob/main/README.md This snippet shows how to use the chat interface to inspect Docker containers. It includes commands to list all containers and their statuses, retrieve container logs, check running processes, and monitor disk usage within a container. ```ruby # Check container status and debug issues response = chat.ask("Show me all containers and their current status") response = chat.ask("Get the logs for the problematic-container") response = chat.ask("Check the running processes in the problematic-container") response = chat.ask("Show disk usage in the problematic-container") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.