public ActionResult InitialContainer(string containerName, string sshKey, double cpu, string ram)
        {
            bool checkContainerNameExist = db.ManageContainer.Any(mc => mc.containername == containerName);

            if (checkContainerNameExist)
            {
                return(Content("ContainerNameExist"));
            }

            Account curUser = GetCurrentUserInfo();

            DockerCommand.InitialContainer(curUser.username, containerName, cpu, ram, sshKey);
            //ManageContainer newContainer = new ManageContainer
            //{
            //    username = "******",
            //    containername = "test",
            //    ip = "192.168.1.2",
            //    port = 7001,
            //    cpu = 1,
            //    ram = "1g",
            //    sshkey = "",
            //    enddate = DateTime.Now.AddDays(3),
            //    status = "Đang chạy",
            //    sshcommand = "ssh [email protected] -p 7001"
            //};

            //db.ManageContainer.Add(newContainer);
            //db.SaveChanges();

            return(Content("Success"));
        }
 public async Task InsertDockerCommandAsync(DockerCommand command)
 {
     _context.DockerCommands.Add(command);
     try {
         await _context.SaveChangesAsync();
     }
     catch (Exception exp) {
         _logger.LogError($"Error in {nameof(InsertDockerCommandAsync)}: " + exp.Message);
     }
 }
Exemple #3
0
        private List <DockerCommand> GetDockerCommands()
        {
            var cmd1 = new DockerCommand
            {
                Command     = "run",
                Description = "Runs a Docker container",
                Examples    = new List <DockerCommandExample> {
                    new DockerCommandExample {
                        Example     = "docker run imageName",
                        Description = "Creates a running container from the image. Pulls it from Docker Hub if the image is not local"
                    },
                    new DockerCommandExample {
                        Example     = "docker run -d -p 8080:3000 imageName",
                        Description = "Runs a container in 'daemon' mode with an external port of 8080 and a container port of 3000."
                    }
                }
            };

            var cmd2 = new DockerCommand
            {
                Command     = "ps",
                Description = "Lists containers",
                Examples    = new List <DockerCommandExample> {
                    new DockerCommandExample {
                        Example     = "docker ps",
                        Description = "Lists all running containers"
                    },
                    new DockerCommandExample {
                        Example     = "docker ps -a",
                        Description = "Lists all containers (even if they are not running)"
                    }
                }
            };

            return(new List <DockerCommand> {
                cmd1, cmd2
            });
        }
 public ActionResult StopContainer(string containerName)
 {
     DockerCommand.StopContainer(containerName);
     return(new EmptyResult());
 }