private async Task <bool> stopContainer(string id) { var stopParameters = new ContainerStopParameters(); stopParameters.WaitBeforeKillSeconds = 30; return(await this.client.Containers.StopContainerAsync(id, stopParameters, this.cancelTokenSource.Token)); }
public async Task StopContainers(List <string> containerIds) { foreach (string containerId in containerIds) { ContainerStopParameters stopParameters = new ContainerStopParameters(); await client.Containers.StopContainerAsync(containerId, stopParameters, CancellationToken.None); } await Refresh(); }
public Task ExecuteAsync(CancellationToken token) { var parameters = new ContainerStopParameters { WaitBeforeKillSeconds = (uint)WaitBeforeKill.TotalSeconds }; return(this.client.Containers.StopContainerAsync(this.module.Name, parameters, token)); }
/// <summary> /// <inheritdoc cref="IDockerManager.StopContainerAsync"/> /// </summary> /// <param name="containerId"></param> /// <returns></returns> public virtual async Task <bool> StopContainerAsync(string containerId) { var parameters = new ContainerStopParameters() { WaitBeforeKillSeconds = 5 }; var success = await Client.Containers.StopContainerAsync(containerId, parameters); return(success); }
private static async Task <bool> StopContainer(ContainerListResponse container) { var stopOptions = new ContainerStopParameters { WaitBeforeKillSeconds = 5 }; bool stopped = await _client.Containers .StopContainerAsync(container.ID, stopOptions, CancellationToken.None); return(stopped); }
public async Task <bool> StopContainerAsync(string containerID, ContainerStopParameters stopParameters = null) { if (stopParameters == null) { stopParameters = new ContainerStopParameters() { WaitBeforeKillSeconds = 30 } } ; return(await _client.Containers.StopContainerAsync(containerID, stopParameters)); }
/// <inheritdoc/> public async Task <bool> StopContainerAsync() { var stopOptions = new ContainerStopParameters { WaitBeforeKillSeconds = 5 }; bool stopped = await _client.Containers .StopContainerAsync(Instance.Id, stopOptions, default); return(stopped); }
private async void button9_Click(object sender, EventArgs e) { if (button9.Text == "操作") { return; } int selectednum = listBox1.SelectedIndex; if (selectednum == -1) { return; } IList <ContainerListResponse> containers = await client.Containers.ListContainersAsync( new ContainersListParameters() { Limit = 10, }); string hostsid = listBox1.SelectedItem.ToString(); if (button9.Text == "开启容器") { ContainerStartParameters cp = new ContainerStartParameters(); await client.Containers.StartContainerAsync(hostsid, cp); MessageBox.Show("已经发送指令", "Success", MessageBoxButtons.OK); } else if (button9.Text == "关闭容器") { ContainerStopParameters csp = new ContainerStopParameters { WaitBeforeKillSeconds = 10 }; var stopped = await client.Containers.StopContainerAsync(hostsid, csp, CancellationToken.None); string stopstr = stopped.ToString(); if (stopstr == "True") { MessageBox.Show("已经关闭", "Success", MessageBoxButtons.OK); } else { MessageBox.Show("出现错误", "Error", MessageBoxButtons.OK); } } }
public async Task <bool> StopContainerAsync(string id, ContainerStopParameters parameters, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } IQueryString queryParameters = new QueryString <ContainerStopParameters>(parameters); // since specified wait timespan can be greater than HttpClient's default, we set the // client timeout to infinite and provide a cancellation token. var response = await this._client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/stop", queryParameters, null, new TimeSpan(Timeout.Infinite), cancellationToken).ConfigureAwait(false); return(response.StatusCode != HttpStatusCode.NotModified); }
public async Task <bool> StopContainerAsync(string id) { using var connection = await _dockerClient.ConnectAsync(); var containers = connection.Containers; try { var parameters = new ContainerStopParameters { WaitBeforeKillSeconds = 10 }; var response = await containers.StopContainerAsync(id, parameters); _logger.LogInformation("Container with id '{Id}' stopped successfully.", id); return(response); } catch (Exception ex) { _logger.LogWarning(ex, "Container with id '{Id}' could not be stopped.", id); return(false); } }
/// <summary> /// Called when the <see cref="Client"/> is ready to handle requests. /// </summary> void Ready() { // TODO: Handle termination of underlying Connection actor. Receive <ListImages>(listImages => { var executeCommand = new Connection.ExecuteCommand(listImages, async(dockerClient, cancellationToken) => { var parameters = new ImagesListParameters { MatchName = listImages.MatchName, All = listImages.All, Filters = listImages.Filters.ToMutable() }; IList <ImagesListResponse> images = await dockerClient.Images.ListImagesAsync(parameters); return(new ImageList(listImages.CorrelationId, images)); }); _connection.Tell(executeCommand, Sender); }); Receive <CreateContainer>(createContainer => { var executeCommand = new Connection.ExecuteCommand(createContainer, async(dockerClient, cancellationToken) => { var parameters = new CreateContainerParameters { Image = createContainer.Image, Name = createContainer.Name, AttachStdout = createContainer.AttachStdOut, AttachStderr = createContainer.AttachStdErr, AttachStdin = createContainer.AttachStdIn, Tty = createContainer.TTY, HostConfig = new HostConfig { // Hard-coded for now. LogConfig = new LogConfig { Type = createContainer.LogType } } // TODO: Add other parameters. }; if (createContainer.EnvironmentVariables.Count > 0) { parameters.Env = createContainer.EnvironmentVariables .Select( environmentVariable => $"{environmentVariable.Key}={environmentVariable.Value}" ) .ToList(); } if (createContainer.Binds.Count > 0) { parameters.HostConfig.Binds = createContainer.Binds .Select( bind => $"{bind.Key}:{bind.Value}" ) .ToList(); } if (createContainer.Ports.Count > 0) { parameters.ExposedPorts = createContainer.Ports.ToDictionary( port => port.Key, port => (object)port.Value ); } CreateContainerResponse response = await dockerClient.Containers.CreateContainerAsync(parameters); return(new ContainerCreated(createContainer.CorrelationId, response)); }); _connection.Tell(executeCommand, Sender); }); Receive <StartContainer>(startContainer => { var executeCommand = new Connection.ExecuteCommand(startContainer, async(dockerClient, cancellationToken) => { ContainerStartParameters parameters = new ContainerStartParameters { DetachKeys = startContainer.DetachKeys }; bool containerWasStarted = await dockerClient.Containers.StartContainerAsync(startContainer.ContainerId, parameters); return(new ContainerStarted(startContainer.CorrelationId, startContainer.ContainerId, alreadyStarted: !containerWasStarted )); }); _connection.Tell(executeCommand, Sender); }); Receive <StopContainer>(stopContainer => { var executeCommand = new Connection.ExecuteCommand(stopContainer, async(dockerClient, cancellationToken) => { var parameters = new ContainerStopParameters { WaitBeforeKillSeconds = stopContainer.WaitBeforeKillSeconds }; bool containerWasStopped = await dockerClient.Containers.StopContainerAsync(stopContainer.ContainerId, parameters, cancellationToken); return(new ContainerStopped(stopContainer.CorrelationId, stopContainer.ContainerId, alreadyStopped: !containerWasStopped )); }); _connection.Tell(executeCommand, Sender); }); Receive <RemoveContainer>(removeContainer => { var executeCommand = new Connection.ExecuteCommand(removeContainer, async(dockerClient, cancellationToken) => { await dockerClient.Containers.RemoveContainerAsync(removeContainer.ContainerId, removeContainer.Parameters); return(new ContainerRemoved(removeContainer.CorrelationId, removeContainer.ContainerId )); }); _connection.Tell(executeCommand, Sender); }); Receive <GetContainerLogs>(getContainerLogs => { Log.Debug("Received GetContainerLogs request '{0}' from '{1}'.", getContainerLogs.CorrelationId, Sender); var executeCommand = new Connection.ExecuteCommand(getContainerLogs, async(dockerClient, cancellationToken) => { Stream responseStream = await dockerClient.Containers.GetContainerLogsAsync( getContainerLogs.ContainerId, getContainerLogs.Parameters, cancellationToken ); return(new StreamedResponse(getContainerLogs.CorrelationId, responseStream, format: StreamedResponseFormat.Log)); }); _connection.Tell(executeCommand, Sender); }); Receive <MonitorContainerEvents>(monitorContainerEvents => { Log.Debug("Received MonitorContainerEvents request '{0}' from '{1}'.", monitorContainerEvents.CorrelationId, Sender); var executeCommand = new Connection.ExecuteCommand(monitorContainerEvents, async(dockerClient, cancellationToken) => { Stream responseStream = await dockerClient.Miscellaneous.MonitorEventsAsync(monitorContainerEvents.Parameters, cancellationToken); return(new StreamedResponse(monitorContainerEvents.CorrelationId, responseStream, format: StreamedResponseFormat.Events)); }); _connection.Tell(executeCommand, Sender); }); Receive <CancelRequest>(cancelRequest => { _connection.Forward(cancelRequest); }); Receive <EventBusActor.Subscribe>(subscribeToDockerEvents => { if (_dockerEventBus == null) { _dockerEventBus = Context.ActorOf( DockerEventBus.Create(Self), name: DockerEventBus.ActorName ); } _dockerEventBus.Forward(subscribeToDockerEvents); }); Receive <EventBusActor.Unsubscribe>(unsubscribeFromDockerEvents => { if (_dockerEventBus == null) { return; } _dockerEventBus.Forward(unsubscribeFromDockerEvents); }); }
public void StopContainer(string id) { var parameter = new ContainerStopParameters(); _client.Containers.StopContainerAsync(id, parameter).Wait(); }