Skip to content

A C# library and framework for running commands inside Docker containers with real-time output streaming

Notifications You must be signed in to change notification settings

TomNaughton/ExecAgent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ExecAgent

ExecAgent is a C# library and framework for running commands inside Docker containers with real-time output streaming. It provides a reusable core library (ExecAgent.Core) that can be used by multiple client applications, such as console apps, web GUIs, or desktop interfaces.


Features

  • Execute commands in any running Docker container.

  • Stream stdout and stderr in real-time.

  • Retrieve command exit codes.

  • Designed for reuse across multiple clients:

    • Console applications
    • Web applications (ASP.NET, SignalR)
    • Desktop GUI apps
  • Cross-platform: works wherever Docker and .NET are supported.


Repository Structure

ExecAgent/
│
├─ ExecAgent.sln              # Visual Studio solution
├─ ExecAgent.Core/            # Core library
├─ ExecAgent.TestApp/         # Test console application
└─ .gitignore
  • ExecAgent.Core: The reusable library handling Docker exec commands and streaming output.
  • ExecAgent.TestApp: Example console client that demonstrates how to use the library.

Getting Started

Prerequisites


Running the Test Console App

  1. Pull a lightweight test container:
docker pull alpine:latest
docker run -d --name execagent-test alpine:latest tail -f /dev/null
  1. Update the container name in ExecAgent.TestApp/Program.cs:
string containerName = "execagent-test";
  1. Run the console app:
dotnet run --project ExecAgent.TestApp

Expected output:

Starting ExecAgent test...
Streaming output:
StdOut: Hello ExecAgent
Execution finished with exit code: 0

Usage in Your Own Projects

  1. Add a reference to the Core library:
dotnet add reference ../ExecAgent.Core/ExecAgent.Core.csproj
  1. Create a DockerExecutor and execute commands:
var executor = new DockerExecutor();
var request = new ExecRequest
{
    Container = "your-container-name",
    Command = new[] { "your", "command" },
    Tty = true
};

var session = await executor.CreateSessionAsync(request, CancellationToken.None);

await foreach (var output in session.StreamAsync(CancellationToken.None))
{
    Console.WriteLine(output.Data);
}

var exitCode = await session.GetExitCodeAsync();
Console.WriteLine($"Command finished with exit code {exitCode}");

Contributing

  • Create a new branch for features or bug fixes (feature/xxx, bugfix/xxx).
  • Make your changes and test locally.
  • Open a pull request against main.

License

This project is open-source and licensed under the MIT License.


Topics / Tags

.NET, C#, Docker, Exec, Streaming, Cross-platform

About

A C# library and framework for running commands inside Docker containers with real-time output streaming

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages