// StartContainerExecAsync will start the process specified by id in detach mode with no connected // stdin, stdout, or stderr pipes. public Task StartContainerExecAsync(string id, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } var parameters = new ContainerExecStartParameters { Detach = true, }; var data = new JsonRequestContent <ContainerExecStartParameters>(parameters, this._client.JsonSerializer); return(this._client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"exec/{id}/start", null, data, null, cancellationToken)); }
public async Task <MultiplexedStream> StartAndAttachContainerExecAsync(string id, bool tty, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } var path = $"exec/{id}/start"; var parameters = new ContainerExecStartParameters { Tty = tty, }; var data = new JsonRequestContent <ContainerExecStartParameters>(parameters, this.Client.JsonSerializer); var stream = await this.Client.MakeRequestForHijackedStreamAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, path, null, null, data, cancellationToken).ConfigureAwait(false); if (!stream.CanCloseWrite) { stream.Dispose(); throw new NotSupportedException("Cannot shutdown write on this transport"); } return(new MultiplexedStream(stream, !tty)); }
public static async Task <bool> RunCommandAsync(string command, string containerId) { //const string id = "EOSCDT"; try { var echo = Encoding.UTF8.GetBytes("ls -al"); //var ping = Encoding.UTF8.GetBytes("/bin/ping -c 3 127.0.0.1"); //var cmdToExecuteCP = Encoding.UTF8.GetBytes("cp -R /data /eosio.contracts/ \n"); var cmdToExecute = Encoding.UTF8.GetBytes(command + "\n"); var config = new ContainerExecCreateParameters { AttachStderr = true, AttachStdin = true, AttachStdout = true, Cmd = new string[] { "env", "TERM=xterm-256color", "bash" }, Detach = false, Tty = false, User = "******", Privileged = true }; var execId = await client.Containers.ExecCreateContainerAsync(containerId, config); logger.Info("ExecCreateContainerAsync {0}", execId.ID); var configStart = new ContainerExecStartParameters { AttachStderr = true, AttachStdin = true, AttachStdout = true, Cmd = new string[] { "env", "TERM=xterm-256color", "bash" }, Detach = false, Tty = false, User = "******", Privileged = true }; var buffer = new byte[1024]; using (var stream = await client.Containers.StartWithConfigContainerExecAsync(execId.ID, configStart, default(CancellationToken))) { //await stream.WriteAsync(cmdToExecuteCP, 0, cmdToExecuteCP.Length, default(CancellationToken)); await stream.WriteAsync(cmdToExecute, 0, cmdToExecute.Length, default(CancellationToken)); stream.CloseWrite(); var result = await stream.ReadOutputAsync(buffer, 0, buffer.Length, default(CancellationToken)); do { String printMe = Encoding.UTF8.GetString(buffer, 0, result.Count); // Strip the local docker path from the output so that when VSCode get it, it can treat it as a relative path logger.Info(printMe.Replace("/data/", "")); result = await stream.ReadOutputAsync(buffer, 0, buffer.Length, default(CancellationToken)); }while (!result.EOF); logger.Info("End EOSIO contract build"); } } catch (Exception ex) { logger.Error("x" + ex.Message); logger.Error("x" + ex.InnerException); logger.Error(ex.StackTrace); } return(true); }