/// <summary>
        /// imageName must be on server already otherwise expect a 404
        /// </summary>
        /// <param name="imageName">name of the image, ex: redis</param>
        /// <returns></returns>
        public async Task<string> DockerRun(string imageName)
        {
            //            docker create
            // if miss - 404 on API
            //    docker pull imagename
            //docker create
            //docker start


            var runParams = new DotNet.Models.CreateContainerParameters();
            
            Config y = new Config();
            runParams.Config = y;

            runParams.Config.Tty = true;
            runParams.Config.AttachStderr = true;
            runParams.Config.AttachStdout = true;
            
            
            runParams.Config.Image = imageName;
            

            var result =  await client.Containers.CreateContainerAsync(runParams);
            var hostconfig = new HostConfig();

            await client.Containers.StartContainerAsync(result.Id, hostconfig);
            return result.Id; 

        }
예제 #2
0
        public async Task<bool> StartContainerAsync(string id, HostConfig hostConfig)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

            string path = string.Format(CultureInfo.InvariantCulture, "containers/{0}/start", id);
            JsonRequestContent<HostConfig> data = null;
            if (hostConfig != null)
            {
                data = new JsonRequestContent<HostConfig>(hostConfig, this.Client.JsonSerializer);
            }
            DockerApiResponse response = await this.Client.MakeRequestAsync(new[] {NoSuchContainerHandler}, HttpMethod.Post, path, null, data);
            return response.StatusCode != HttpStatusCode.NotModified;
        }