public static CommandResponse <string> Export(this DockerUri host, string id, string fqFilePath, ICertificatePaths certificates = null) { var arg = $"{host.RenderBaseArgs(certificates)} export"; return(new ProcessExecutor <NoLineResponseParser, string>("docker".ResolveBinary(), $"{arg} -o {fqFilePath} {id}").Execute()); }
public static CommandResponse <string> ExecuteCommandInContainer(this DockerUri host, string id, string options, string args, string command, ICertificatePaths certificates = null) { var arg = $"{host.RenderBaseArgs(certificates)}"; return(new ProcessExecutor <GeneralResponseParser, string>("docker".ResolveBinary(), $"{arg} exec {options} {id} {args} \"{command}\"").Execute()); }
public static CommandResponse <string> CopyToContainer(this DockerUri host, string id, string containerPath, string hostPath, ICertificatePaths certificates = null) { var arg = $"{host.RenderBaseArgs(certificates)}"; return(new ProcessExecutor <IgnoreErrorResponseParser, string>("docker".ResolveBinary(), $"{arg} cp \"{hostPath}\" {id}:{containerPath}").Execute()); }
public static CommandResponse <IList <string> > ComposeCreate(this DockerUri host, string altProjectName = null, bool forceRecreate = false, bool noRecreate = false, bool dontBuild = false, bool buildBeforeCreate = false, string[] services = null /*all*/, ICertificatePaths certificates = null, params string[] composeFile) { var cwd = WorkingDirectory(composeFile); var args = $"{host.RenderBaseArgs(certificates)}"; if (null != composeFile && 0 != composeFile.Length) { foreach (var cf in composeFile) { if (!string.IsNullOrEmpty(cf)) { args += $" -f \"{cf}\""; } } } if (!string.IsNullOrEmpty(altProjectName)) { args += $" -p {altProjectName}"; } var options = string.Empty; if (forceRecreate) { options += " --force-recreate"; } if (noRecreate) { options += " --no-recreate"; } if (dontBuild) { options += " --no-build"; } if (buildBeforeCreate) { options += " --build"; } if (null != services && 0 != services.Length) { options += " " + string.Join(" ", services); } return (new ProcessExecutor <StringListResponseParser, IList <string> >( "docker-compose".ResolveBinary(), $"{args} create {options}", cwd.NeedCwd ? cwd.Cwd : null).Execute()); }
public static CommandResponse <IList <string> > Logout(this DockerUri host, ICertificatePaths certificates = null) { var args = $"{host.RenderBaseArgs(certificates)}"; return (new ProcessExecutor <StringListResponseParser, IList <string> >( "docker".ResolveBinary(), $"{args} logout").Execute()); }
public DockerContainerService(string name, string id, DockerUri docker, ServiceRunningState state, ICertificatePaths certificates, bool stopOnDispose = true, bool removeOnDispose = true, bool removeMountOnDispose = false, bool removeNamedMountOnDispose = false, bool isWindowsContainer = false, string instanceId = null, string project = null) : this(name, id, docker, state, certificates, null, stopOnDispose, removeOnDispose, removeMountOnDispose, removeNamedMountOnDispose, isWindowsContainer, instanceId, project) { }
public DockerImageService(string name, string id, string tag, DockerUri dockerHost, ICertificatePaths certificate) : base(name) { Id = id; Tag = tag; Certificates = certificate; DockerHost = dockerHost; State = ServiceRunningState.Running; }
public DockerNetworkService(string name, string id, DockerUri dockerHost, ICertificatePaths certificate, bool removeOnDispose = false) : base(name) { _removeOnDispose = removeOnDispose; Id = id; DockerHost = dockerHost; Certificates = certificate; }
public static CommandResponse <IList <string> > UnPause(this DockerUri host, ICertificatePaths certificates = null, params string[] containerIds) { var args = $"{host.RenderBaseArgs(certificates)}"; return (new ProcessExecutor <StringListResponseParser, IList <string> >( "docker".ResolveBinary(), $"{args} unpause {string.Join(" ", containerIds)}").Execute()); }
/// <summary> /// Get the docker version both client and server version. It includes the server operating system (linux, windows). /// </summary> /// <param name="host">The docker daemon to contact.</param> /// <param name="certificates">Path to certificates if any.</param> /// <returns>A response with the versions if successful.</returns> public static CommandResponse <DockerInfoBase> Version(this DockerUri host, ICertificatePaths certificates = null) { var args = $"{host.RenderBaseArgs(certificates)}"; var fmt = "{{.Server.Version}};{{.Server.APIVersion}};{{.Client.Version}};{{.Client.APIVersion}};{{.Server.Os}}"; return (new ProcessExecutor <BaseInfoResponseParser, DockerInfoBase>( "docker".ResolveBinary(), $"{args} version -f \"{fmt}\"").Execute()); }
public static CommandResponse <IList <string> > NetworkRm(this DockerUri host, ICertificatePaths certificates = null, params string[] network) { var args = $"{host.RenderBaseArgs(certificates)}"; return (new ProcessExecutor <StringListResponseParser, IList <string> >( "docker".ResolveBinary(), $"{args} network rm {string.Join(" ", network)}").Execute()); }
public static CommandResponse <IList <string> > ComposeBuild(this DockerUri host, string altProjectName = null, bool forceRm = false, bool dontUseCache = false, bool alwaysPull = false, string[] services = null /*all*/, IDictionary <string, string> env = null, ICertificatePaths certificates = null, params string[] composeFile) { var cwd = WorkingDirectory(composeFile); var args = $"{host.RenderBaseArgs(certificates)}"; if (null != composeFile && 0 != composeFile.Length) { foreach (var cf in composeFile) { if (!string.IsNullOrEmpty(cf)) { args += $" -f \"{cf}\""; } } } if (!string.IsNullOrEmpty(altProjectName)) { args += $" -p {altProjectName}"; } var options = string.Empty; if (forceRm) { options += " --force-rm"; } if (alwaysPull) { options += " --pull"; } if (forceRm) { options += " --force-rm"; } if (null != services && 0 != services.Length) { options += " " + string.Join(" ", services); } return (new ProcessExecutor <StringListResponseParser, IList <string> >( "docker-compose".ResolveBinary(), $"{args} build {options}", cwd.NeedCwd ? cwd.Cwd : null).ExecutionEnvironment(env).Execute()); }
public static CommandResponse <IList <Volume> > VolumeInspect(this DockerUri host, ICertificatePaths certificates = null, params string[] volume) { var args = $"{host.RenderBaseArgs(certificates)}"; var volumes = string.Join(" ", volume); return (new ProcessExecutor <VolumeInspectResponseParser, IList <Volume> >( "docker".ResolveBinary(), $"{args} volume inspect {volumes}").Execute()); }
public static ConsoleStream <string> ComposeLogs(this DockerUri host, string altProjectName = null, string composeFile = null, string[] services = null /*all*/, CancellationToken cancellationToken = default(CancellationToken), bool follow = false, bool showTimeStamps = false, DateTime?since = null, int?numLines = null, bool noColor = false, ICertificatePaths certificates = null) { var args = $"{host.RenderBaseArgs(certificates)}"; if (!string.IsNullOrEmpty(composeFile)) { args += $" -f {composeFile}"; } if (!string.IsNullOrEmpty(altProjectName)) { args += $" -p {altProjectName}"; } var options = string.Empty; if (follow) { options += " -f"; } if (null != since) { options += $" --since {since}"; } options += numLines.HasValue ? $" --tail={numLines}" : " --tail=all"; if (showTimeStamps) { options += " -t"; } if (noColor) { options += " --no-color"; } if (null != services && 0 != services.Length) { options += " " + string.Join(" ", services); } return (new StreamProcessExecutor <StringMapper, string>( "docker-compose".ResolveBinary(), $"{args} logs {options}").Execute(cancellationToken)); }
public DockerContainerService(string name, string id, DockerUri docker, ServiceRunningState state, ICertificatePaths certificates, bool stopOnDispose = true, bool removeOnDispose = true) { _certificates = certificates; _stopOnDispose = stopOnDispose; _removeOnDispose = removeOnDispose; Name = name; Id = id; DockerHost = docker; State = state; }
// TODO: Implement me! public static CommandResponse <IList <string> > ServiceCreate(this DockerUri host, Orchestrator orchestrator = Orchestrator.All, string kubeConfigFile = null, ICertificatePaths certificates = null, params string [] stacks) { var args = $"{host.RenderBaseArgs(certificates)}"; var opts = $"--orchestrator={orchestrator}"; // TODO: return // TODO: (new ProcessExecutor <StringListResponseParser, IList <string> >( "docker".ResolveBinary(), $"{args} stack rm {opts} {string.Join(" ", stacks)}").Execute()); }
public static CommandResponse <NetworkConfiguration> NetworkInspect(this DockerUri host, ICertificatePaths certificates = null, params string[] network) { var args = $"{host.RenderBaseArgs(certificates)}"; var options = string.Empty; options += string.Join(" ", network); return (new ProcessExecutor <NetworkLsResponseParser, NetworkConfiguration>( "docker".ResolveBinary(), $"{args} network inspect {options}").Execute()); }
public static CommandResponse <string> WindowsDaemon(this DockerUri host, ICertificatePaths certificates = null) { var version = host.Version(certificates); if (version.Data.ServerOs.ToLower().Equals("windows")) { return(new CommandResponse <string>(true, new string[0])); } var args = $"{host.RenderBaseArgs(certificates)}"; return(new ProcessExecutor <NoLineResponseParser, string>( "dockercli".ResolveBinary(), $"{args} -SwitchDaemon").Execute()); }
public static CommandResponse <IList <DockerImageRowResponse> > Images(this DockerUri host, string filter = null, ICertificatePaths certificates = null) { var options = "--quiet --no-trunc --format \"{{.ID}};{{.Repository}};{{.Tag}}\""; if (!string.IsNullOrEmpty(filter)) { options = $" --filter={filter}"; } return (new ProcessExecutor <ClientImagesResponseParser, IList <DockerImageRowResponse> >( "docker".ResolveBinary(), $"{host.RenderBaseArgs(certificates)} images {options}").Execute()); }
internal EngineScope(DockerUri host, EngineScopeType scope, ICertificatePaths certificates = null) { Scope = scope; _host = host; _certificates = certificates; _original = host.IsWindowsEngine(certificates) ? EngineScopeType.Windows : EngineScopeType.Linux; if (scope == _original) { return; } SwitchToScope(Scope); }
public static CommandResponse <IList <string> > ComposeDown(this DockerUri host, string altProjectName = null, ImageRemovalOption removeImagesFrom = ImageRemovalOption.None, bool removeVolumes = false, bool removeOrphanContainers = false, IDictionary <string, string> env = null, ICertificatePaths certificates = null, params string[] composeFile) { var cwd = WorkingDirectory(composeFile); var args = $"{host.RenderBaseArgs(certificates)}"; if (null != composeFile && 0 != composeFile.Length) { foreach (var cf in composeFile) { if (!string.IsNullOrEmpty(cf)) { args += $" -f \"{cf}\""; } } } if (!string.IsNullOrEmpty(altProjectName)) { args += $" -p {altProjectName}"; } var options = string.Empty; if (removeOrphanContainers) { options += " --remove-orphans"; } if (removeVolumes) { options += " -v"; } if (removeImagesFrom != ImageRemovalOption.None) { options += removeImagesFrom == ImageRemovalOption.Local ? " --rmi local" : " --rmi all"; } return (new ProcessExecutor <StringListResponseParser, IList <string> >( "docker-compose".ResolveBinary(), $"{args} down {options}", cwd.NeedCwd ? cwd.Cwd : null).ExecutionEnvironment(env).Execute()); }
public static CommandResponse <string> Stop(this DockerUri host, string id, TimeSpan?killTimeout = null, ICertificatePaths certificates = null) { var arg = $"{host.RenderBaseArgs(certificates)} stop"; if (null != killTimeout) { arg += $" --time={Math.Round(killTimeout.Value.TotalSeconds, 0)}"; } arg += $" {id}"; return(new ProcessExecutor <SingleStringResponseParser, string>( "docker".ResolveBinary(), arg).Execute()); }
public static CommandResponse <IList <string> > VolumeRm(this DockerUri host, ICertificatePaths certificates = null, bool force = false, params string[] volume) { var args = $"{host.RenderBaseArgs(certificates)}"; var opts = string.Empty; if (force) { opts = "-f"; } var volumes = string.Join(" ", volume); return (new ProcessExecutor <StringListResponseParser, IList <string> >( "docker".ResolveBinary(), $"{args} volume rm {opts} {volumes}").Execute()); }
public DockerContainerService(string name, string id, DockerUri docker, ServiceRunningState state, ICertificatePaths certificates, bool stopOnDispose = true, bool removeOnDispose = true, bool removeMountOnDispose = false, bool removeNamedMountOnDispose = false, bool isWindowsContainer = false) { IsWindowsContainer = isWindowsContainer; Certificates = certificates; _removeNamedMountOnDispose = removeNamedMountOnDispose; _removeMountOnDispose = removeMountOnDispose; StopOnDispose = stopOnDispose; RemoveOnDispose = removeOnDispose; Name = name; Id = id; DockerHost = docker; State = state; }
public static CommandResponse <string> Run(this DockerUri host, string image, ContainerCreateParams args = null, ICertificatePaths certificates = null) { var arg = $"{host.RenderBaseArgs(certificates)} run -d"; if (null != args) { arg += " " + args; } arg += " " + image; return (new ProcessExecutor <SingleStringResponseParser, string>( "docker".ResolveBinary(), arg).Execute()); }
public static CommandResponse <IList <NetworkRow> > NetworkLs(this DockerUri host, ICertificatePaths certificates = null, params string[] filters) { var args = $"{host.RenderBaseArgs(certificates)}"; var options = $" --no-trunc --format \"{NetworkLsResponseParser.Format}\""; if (null != filters && 0 != filters.Length) { options = filters.Aggregate(options, (current, filter) => current + $" --filter={filter}"); } return (new ProcessExecutor <NetworkLsResponseParser, IList <NetworkRow> >( "docker".ResolveBinary(), $"{args} network ls {options}").Execute()); }
public static CommandResponse <IList <string> > ComposeScale(this DockerUri host, string altProjectName = null, TimeSpan?shutdownTimeout = null, string[] serviceEqNumber = null /*all*/, IDictionary <string, string> env = null, ICertificatePaths certificates = null, params string[] composeFile) { var cwd = WorkingDirectory(composeFile); var args = $"{host.RenderBaseArgs(certificates)}"; if (null != composeFile && 0 != composeFile.Length) { foreach (var cf in composeFile) { if (!string.IsNullOrEmpty(cf)) { args += $" -f \"{cf}\""; } } } if (!string.IsNullOrEmpty(altProjectName)) { args += $" -p {altProjectName}"; } var options = string.Empty; if (null != shutdownTimeout) { options = $" -t {Math.Round(shutdownTimeout.Value.TotalSeconds, 0)}"; } var services = string.Empty; if (null != serviceEqNumber && 0 != serviceEqNumber.Length) { services += " " + string.Join(" ", serviceEqNumber); } return (new ProcessExecutor <StringListResponseParser, IList <string> >( "docker-compose".ResolveBinary(), $"{args} scale {options} {services}", cwd.NeedCwd ? cwd.Cwd : null).ExecutionEnvironment(env).Execute()); }
public static CommandResponse <IList <string> > NetworkDisconnect(this DockerUri host, string container, string network, bool force = false, ICertificatePaths certificates = null) { var args = $"{host.RenderBaseArgs(certificates)}"; var options = string.Empty; if (force) { options += " -f"; } return (new ProcessExecutor <StringListResponseParser, IList <string> >( "docker".ResolveBinary(), $"{args} network disconnect {options} {network} {container}").Execute()); }
public static CommandResponse <IList <string> > NetworkConnect(this DockerUri host, string container, string network, string[] alias = null, string ipv4 = null, string ipv6 = null, ICertificatePaths certificates = null, params string[] links) { var args = $"{host.RenderBaseArgs(certificates)}"; var options = new StringBuilder(); options.OptionIfExists("--alias=", alias) .OptionIfExists("--ip ", ipv4) .OptionIfExists("--ipv6 ", ipv6) .OptionIfExists("--link=", links); return (new ProcessExecutor <StringListResponseParser, IList <string> >( "docker".ResolveBinary(), $"{args} network connect {options} {network} {container}").Execute()); }
public static CommandResponse <IList <string> > NetworkInspect(this DockerUri host, string format = null, ICertificatePaths certificates = null, params string[] network) { var args = $"{host.RenderBaseArgs(certificates)}"; var options = string.Empty; if (!string.IsNullOrEmpty(format)) { options += $" --format={format}"; } options += string.Join(" ", network); return (new ProcessExecutor <StringListResponseParser, IList <string> >( "docker".ResolveBinary(), $"{args} network disconnect {options}").Execute()); }