1、引入nuget包
Install-Package Docker.DotNet
2、示例如下,更加详细命令查看文档 https://github.com/dotnet/Docker.DotNet
//创建客户端
using var client = new DockerClientConfiguration() .CreateClient();
//查找容器列表 IList<ContainerListResponse> containers = await client.Containers.ListContainersAsync( new ContainersListParameters() { Limit = 10, }); foreach (var item in containers) { //根据容器名称过滤容器,然后重启 if (item.Names.Any(x => x == "/wvp_pro_compose-wvpRedis-1")) await client.Containers.RestartContainerAsync(item.ID, new ContainerRestartParameters() { WaitBeforeKillSeconds = 1 }, CancellationToken.None); }
3、如果是通过docker容器运行的.NET程序,需要挂载docker的sock文件
docker run -v /var/run/docker.sock:/var/run/docker.sock
参考文档:
标签:CORE,run,sock,var,new,NET,docker From: https://www.cnblogs.com/arthaslcm/p/16952537.html