Пример #1
0
        public IEnumerable <Image> Get()
        {
            IEnumerable <Image> list = null;

#if DEBUG
            var content = System.IO.File.ReadAllText("wwwroot/resource/data/imageList.json");
            list = JsonConvert.DeserializeObject <Image[]>(content);
#else
            DockerClientUtils.UseDockerClient(client =>
            {
                list = client.Images.ListImagesAsync(new ImagesListParameters())
                       .Result
                       .Select(t => new Model.Image()
                {
                    Id          = t.ID,
                    Created     = t.Created,
                    SharedSize  = t.SharedSize,
                    Size        = t.Size,
                    VirtualSize = t.VirtualSize,
                    RepoTags    = string.Join(",", t.RepoTags),
                    Labels      = t.Labels
                });
            });
#endif
            return(list);
        }
Пример #2
0
 public IActionResult Create([FromBody] CreateContainerConfig config)
 {
     try
     {
         string id = null;
         DockerClientUtils.UseDockerClient(client =>
         {
             var ret = client.Containers.CreateContainerAsync(new CreateContainerParameters()
             {
                 Shell            = config.Shell,
                 Entrypoint       = config.Entrypoint,
                 WorkingDir       = config.WorkingDir,
                 Volumes          = config.Volumes,
                 Image            = config.Image,
                 Cmd              = config.Cmd,
                 Env              = config.Env,
                 ExposedPorts     = config.ExposedPorts,
                 Name             = config.Name,
                 HostConfig       = config.HostConfig,
                 NetworkingConfig = config.NetworkingConfig
             }).Result;
             id = ret.ID;
         });
         return(new ObjectResult(Get(id)));
     }
     catch (Exception ex)
     {
         return(base.StatusCode(500, $"Add Error.\r\n{ExceptionUtils.GetExceptionMessage(ex)}"));
     }
 }
Пример #3
0
        public IEnumerable <Container> Get()
        {
            IEnumerable <Container> list = null;

#if DEBUG
            var content = System.IO.File.ReadAllText("wwwroot/resource/data/containerList.json");
            list = JsonConvert.DeserializeObject <Container[]>(content);
#else
            DockerClientUtils.UseDockerClient(client =>
            {
                list = client.Containers.ListContainersAsync(new ContainersListParameters()
                {
                    All = true
                })
                       .Result
                       .Select(t => new Model.Container()
                {
                    Id      = t.ID,
                    Name    = t.Names?.LastOrDefault().Substring(1),
                    Port    = string.Join(", ", t.Ports?.Select(p => $"{p.IP}:{p.PublicPort}->{p.PrivatePort}/{p.Type}")),
                    Command = t.Command,
                    Created = t.Created,
                    Image   = t.Image,
                    Status  = t.Status
                });
            });
#endif
            return(list);
        }
Пример #4
0
 public IActionResult Delete(string id)
 {
     try
     {
         DockerClientUtils.UseDockerClient(client =>
         {
             client.Images.DeleteImageAsync(id, new ImageDeleteParameters()).Wait();
         });
         return(base.Ok());
     }
     catch (Exception ex)
     {
         return(base.StatusCode(500, $"Delete Error.\r\n{ExceptionUtils.GetExceptionMessage(ex)}"));
     }
 }
Пример #5
0
 public IActionResult Delete(string id)
 {
     try
     {
         if (id.StartsWith(Environment.MachineName))
         {
             return(base.StatusCode(403, $"Can't operate SimpleDockerUI container."));
         }
         DockerClientUtils.UseDockerClient(client =>
         {
             client.Containers.RemoveContainerAsync(id, new ContainerRemoveParameters()
             {
             }).Wait();
         });
         return(base.Ok());
     }
     catch (Exception ex)
     {
         return(base.StatusCode(500, $"Delete Error.\r\n{ExceptionUtils.GetExceptionMessage(ex)}"));
     }
 }
Пример #6
0
 public IActionResult Stop(string id)
 {
     try
     {
         if (id.StartsWith(Environment.MachineName))
         {
             return(base.StatusCode(403, $"Can't operate SimpleDockerUI container."));
         }
         bool ret = false;
         DockerClientUtils.UseDockerClient(client =>
         {
             ret = client.Containers.StopContainerAsync(id, new ContainerStopParameters()).Result;
         });
         if (ret)
         {
             return(base.Ok());
         }
         return(base.StatusCode(500, $"Stop Error.\r\nStop Method return 'false'."));
     }
     catch (Exception ex)
     {
         return(base.StatusCode(500, $"Stop Error.\r\n{ExceptionUtils.GetExceptionMessage(ex)}"));
     }
 }