Docker
DockerTools enable an Agent to interact with Docker containers, images, volumes, and networks.
Prerequisites
The Docker tools require the docker Python package. You'll also need Docker installed and running on your system.
1uv pip install dockerExample
The following example creates an agent that can manage Docker resources:
1import sys2from kern.agent import Agent34try:5 from kern.tools.docker import DockerTools67 docker_tools = DockerTools(8 enable_container_management=True,9 enable_image_management=True,10 enable_volume_management=True,11 enable_network_management=True,12 )1314 # Create an agent with Docker tools15 docker_agent = Agent(16 name="Docker Agent",17 instructions=[18 "You are a Docker management assistant that can perform various Docker operations.",19 "You can manage containers, images, volumes, and networks.",20 ],21 tools=[docker_tools],22 markdown=True,23 )2425 # Example: List all running Docker containers26 docker_agent.print_response("List all running Docker containers", stream=True)2728 # Example: Pull and run an NGINX container29 docker_agent.print_response("Pull the latest nginx image", stream=True)30 docker_agent.print_response("Run an nginx container named 'web-server' on port 8080", stream=True)3132except ValueError as e:33 print(f"\n❌ Docker Tool Error: {e}")34 print("\n🔍 Troubleshooting steps:")3536 if sys.platform == "darwin": # macOS37 print("1. Ensure Docker Desktop is running")38 print("2. Check Docker Desktop settings")39 print("3. Try running 'docker ps' in terminal to verify access")4041 elif sys.platform == "linux":42 print("1. Check if Docker service is running:")43 print(" systemctl status docker")44 print("2. Make sure your user has permissions to access Docker:")45 print(" sudo usermod -aG docker $USER")4647 elif sys.platform == "win32":48 print("1. Ensure Docker Desktop is running")49 print("2. Check Docker Desktop settings")Toolkit Params
| Parameter | Type | Default | Description |
|---|---|---|---|
enable_container_management | bool | True | Enables container management functions (list, start, stop, etc.) |
enable_image_management | bool | True | Enables image management functions (pull, build, etc.) |
enable_volume_management | bool | False | Enables volume management functions |
enable_network_management | bool | False | Enables network management functions |
Toolkit Functions
Container Management
| Function | Description |
|---|---|
list_containers | Lists all containers or only running containers |
start_container | Starts a stopped container |
stop_container | Stops a running container |
remove_container | Removes a container |
get_container_logs | Retrieves logs from a container |
inspect_container | Gets detailed information about a container |
run_container | Creates and starts a new container |
exec_in_container | Executes a command inside a running container |
Image Management
| Function | Description |
|---|---|
list_images | Lists all images on the system |
pull_image | Pulls an image from a registry |
remove_image | Removes an image |
build_image | Builds an image from a Dockerfile |
tag_image | Tags an image |
inspect_image | Gets detailed information about an image |
Volume Management
| Function | Description |
|---|---|
list_volumes | Lists all volumes |
create_volume | Creates a new volume |
remove_volume | Removes a volume |
inspect_volume | Gets detailed information about a volume |
Network Management
| Function | Description |
|---|---|
list_networks | Lists all networks |
create_network | Creates a new network |
remove_network | Removes a network |
inspect_network | Gets detailed information about a network |
connect_container_to_network | Connects a container to a network |
disconnect_container_from_network | Disconnects a container from a network |
Developer Resources
- View Tools