added functionality to specify container to run
This commit is contained in:
@@ -93,6 +93,22 @@ func BuildRunContainer(NumPorts int, GPU string, ContainerName string) (*DockerV
|
||||
}
|
||||
RespDocker.ImagePath = config.DefaultDockerFile
|
||||
|
||||
if ContainerName != "" {
|
||||
Containers, err := ViewAllContainers()
|
||||
if err != nil {
|
||||
return nil,err
|
||||
}
|
||||
for _, dockerContainer := range Containers.DockerContainer {
|
||||
if dockerContainer.ContainerName == ContainerName {
|
||||
RespDocker.ImagePath = config.DockerContainers + ContainerName + "/"
|
||||
break
|
||||
}
|
||||
}
|
||||
if RespDocker.ImagePath == config.DefaultDockerFile {
|
||||
return nil, errors.New("Container " + ContainerName + " does not exist in the server")
|
||||
}
|
||||
}
|
||||
|
||||
// Gets docker information from env variables
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
||||
if err != nil {
|
||||
|
||||
@@ -97,6 +97,7 @@ func Server() error{
|
||||
// Get Number of ports to open and whether to use GPU or not
|
||||
Ports := c.DefaultQuery("ports","0")
|
||||
GPU := c.DefaultQuery("GPU","false")
|
||||
ContainerName := c.DefaultQuery("ContainerName","")
|
||||
var PortsInt int
|
||||
|
||||
// Convert Get Request value to int
|
||||
@@ -104,7 +105,7 @@ func Server() error{
|
||||
|
||||
// Creates container and returns-back result to
|
||||
// access container
|
||||
resp, err := docker.BuildRunContainer(PortsInt,GPU,"")
|
||||
resp, err := docker.BuildRunContainer(PortsInt,GPU,ContainerName)
|
||||
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
||||
|
||||
Reference in New Issue
Block a user