Ejemplo n.º 1
0
        /// <inheritdoc cref="IContainerManager" />
        public async Task <string> LaunchEngineContainerAsync(ContainerScale scale, string instanceId)
        {
            var hostIp = await this.GetIpFromInstanceAsync(instanceId);

            var    docker  = this.CreateClientFromHost(hostIp);
            string imageId = await this.GetImageIdAsync(docker, instanceId);

            int availablePort = await this.SelectAvailablePortAsync(docker);

            var createParams = this.CreateDefaultContainerParameters(scale, imageId, availablePort);

            if (scale.Type == ContainerType.GPU)
            {
                createParams.Env = new List <string>()
                {
                    "NVIDIA_VISIBLE_DEVICES=all",
                };
                createParams.HostConfig.Runtime = GpuRuntime;
            }

            var createdContainer = await docker.Containers.CreateContainerAsync(createParams);

            await docker.Containers.StartContainerAsync(createdContainer.ID, new ContainerStartParameters());

            return(createdContainer.ID);
        }
Ejemplo n.º 2
0
 private CreateContainerParameters CreateDefaultContainerParameters(ContainerScale scale, string imageId, int port) => new CreateContainerParameters()
 {
     Image        = imageId,
     ExposedPorts = new Dictionary <string, EmptyStruct>()
     {
         { $"{ContainerPort}/tcp", default(EmptyStruct) },
     },
     Env = new List <string>()
     {
         $"ENGINE_NAME={scale.Type.ToEngineName()}",
     },
     HostConfig = new HostConfig()
     {
         CPUCount     = scale.Cores,
         Memory       = (1024 * 1024) * scale.MemoryMegabytes,
         Runtime      = GpuRuntime,
         PortBindings = new Dictionary <string, IList <PortBinding> >()
         {
             {
                 $"{ContainerPort}/tcp", new List <PortBinding>()
                 {
                     new PortBinding()
                     {
                         HostPort = port.ToString(),
                     },
                 }
             },
         },
         Binds = new List <string>()
         {
             $"{TablebaseLocation}:{TablebaseLocation}:ro",
         },
     },
 };