From f4549b74ac58fc3c30f52d6a371a2bf3e5563625 Mon Sep 17 00:00:00 2001 From: Josh Garverick Date: Fri, 3 Oct 2014 07:39:34 -0400 Subject: [PATCH 1/2] Adding support for naming a container when using CreateContainer --- Docker.DotNet/ContainerOperations.cs | 8 +++++++- Docker.DotNet/Models/CreateContainerParameters.cs | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Docker.DotNet/ContainerOperations.cs b/Docker.DotNet/ContainerOperations.cs index 235800487..f4f24501c 100644 --- a/Docker.DotNet/ContainerOperations.cs +++ b/Docker.DotNet/ContainerOperations.cs @@ -54,10 +54,16 @@ public async Task InspectContainerAsync(string id) public async Task CreateContainerAsync(CreateContainerParameters parameters) { + IQueryString qs = null; + if (parameters == null) { throw new ArgumentNullException("parameters"); } + if (!string.IsNullOrEmpty(parameters.ContainerName)) { + qs = new QueryString(parameters.ContainerName); + } + string path = "containers/create"; JsonRequestContent data = null; @@ -65,7 +71,7 @@ public async Task CreateContainerAsync(CreateContainerP { data = new JsonRequestContent(parameters.Config, this.Client.JsonSerializer); } - DockerApiResponse response = await this.Client.MakeRequestAsync(new[] {NoSuchContainerHandler}, HttpMethod.Post, path, null, data); + DockerApiResponse response = await this.Client.MakeRequestAsync(new[] {NoSuchContainerHandler}, HttpMethod.Post, path, qs, data); return this.Client.JsonSerializer.DeserializeObject(response.Body); } diff --git a/Docker.DotNet/Models/CreateContainerParameters.cs b/Docker.DotNet/Models/CreateContainerParameters.cs index 831c1f57b..eb363d189 100644 --- a/Docker.DotNet/Models/CreateContainerParameters.cs +++ b/Docker.DotNet/Models/CreateContainerParameters.cs @@ -4,6 +4,9 @@ public class CreateContainerParameters { public Config Config { get; set; } + [QueryStringParameter("name", false)] + public string ContainerName { get; set; } + public CreateContainerParameters() { } From 2b3ca06fba7d66a439052257181bbd1fb33fe3b0 Mon Sep 17 00:00:00 2001 From: Josh Garverick Date: Mon, 6 Oct 2014 20:58:02 -0400 Subject: [PATCH 2/2] Code fixes for PR #7 --- Docker.DotNet/ContainerOperations.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Docker.DotNet/ContainerOperations.cs b/Docker.DotNet/ContainerOperations.cs index f4f24501c..26401bd31 100644 --- a/Docker.DotNet/ContainerOperations.cs +++ b/Docker.DotNet/ContainerOperations.cs @@ -60,10 +60,10 @@ public async Task CreateContainerAsync(CreateContainerP { throw new ArgumentNullException("parameters"); } + if (!string.IsNullOrEmpty(parameters.ContainerName)) { - qs = new QueryString(parameters.ContainerName); + qs = new QueryString(parameters); } - string path = "containers/create"; JsonRequestContent data = null;