Beispiel #1
0
 /// <summary>
 /// Gets a single container object from the client by id.
 /// </summary>
 /// <param name="id">The container identifier to retrieve.</param>
 /// <param name="dkrClient">The client to request the container from.</param>
 /// <returns>The single container object matching the id.</returns>
 internal static ContainerListResponse GetContainerById(string id, DotNet.DockerClient dkrClient)
 {
     // TODO - Have a better way to get the container list response given the ID.
     return(dkrClient.Containers.ListContainersAsync(new ContainersListParameters()
     {
         All = true
     }).AwaitResult(
                ).Single(c => c.ID.StartsWith(id) || c.Names.Any(n => n.Equals("/" + id))));
 }
        /// <summary>
        /// Gets a single image object from the client by id.
        /// </summary>
        /// <param name="id">The image identifier to retrieve.</param>
        /// <param name="dkrClient">The client to request the image from.</param>
        /// <returns>The single image object matching the id.</returns>
        internal static async Task <ImagesListResponse> GetImageById(string id, DotNet.DockerClient dkrClient)
        {
            var shaId = id;

            if (!shaId.StartsWith("sha256:"))
            {
                shaId = "sha256:" + shaId;
            }
            // TODO - Have a better way to get the image list response given the ID.
            return((await dkrClient.Images.ListImagesAsync(new ImagesListParameters()
            {
                All = true
            }))
                   .Single(i => i.ID.StartsWith(shaId)));
        }
        /// <summary>
        /// Creates the container
        /// </summary>
        /// <param name="id"></param>
        /// <param name="cmdlet"></param>
        /// <param name="dkrClient"></param>
        /// <returns></returns>
        internal static Task <CreateContainerResponse> CreateContainer(
            string id,
            CreateContainerCmdlet cmdlet,
            DotNet.DockerClient dkrClient)
        {
            var configuration = cmdlet.Configuration;

            if (configuration == null)
            {
                configuration = new Config();
            }

            if (!String.IsNullOrEmpty(id))
            {
                configuration.Image = id;
            }

            if (cmdlet.Command != null)
            {
                configuration.Cmd = cmdlet.Command;
            }

            var hostConfiguration = cmdlet.HostConfiguration;

            if (hostConfiguration == null)
            {
                hostConfiguration = new HostConfig();
            }

            if (String.IsNullOrEmpty(hostConfiguration.Isolation))
            {
                hostConfiguration.Isolation = cmdlet.Isolation.ToString();
            }

            configuration.Tty          = cmdlet.Terminal;
            configuration.OpenStdin    = cmdlet.Input;
            configuration.AttachStdin  = cmdlet.Input;
            configuration.AttachStdout = true;
            configuration.AttachStderr = true;

            return(dkrClient.Containers.CreateContainerAsync(
                       new CreateContainerParameters(configuration)
            {
                Name = cmdlet.Name,
                HostConfig = hostConfiguration
            }));
        }
Beispiel #4
0
        /// <summary>
        /// Creates the container
        /// </summary>
        /// <param name="id"></param>
        /// <param name="cmdlet"></param>
        /// <param name="dkrClient"></param>
        /// <returns></returns>
        internal static CreateContainerResponse CreateContainer(
            string id,
            CreateContainerCmdlet cmdlet,
            DotNet.DockerClient dkrClient)
        {
            var configuration = cmdlet.Configuration;

            if (configuration == null)
            {
                configuration = new Config();
            }

            if (!String.IsNullOrEmpty(id))
            {
                configuration.Image = id;
            }

            if (cmdlet.Command != null)
            {
                configuration.Cmd = cmdlet.Command;
            }

            var hostConfiguration = cmdlet.HostConfiguration;

            if (hostConfiguration == null)
            {
                hostConfiguration = new HostConfig();
            }

            if (String.IsNullOrEmpty(hostConfiguration.Isolation))
            {
                hostConfiguration.Isolation = cmdlet.Isolation.ToString();
            }

            return(dkrClient.Containers.CreateContainerAsync(
                       new CreateContainerParameters(configuration)
            {
                Name = cmdlet.ContainerName,
                HostConfig = hostConfiguration
            }).AwaitResult());
        }
 internal static Task <IList <ContainerListResponse> > GetContainersByName(string name, DotNet.DockerClient dkrClient)
 {
     return(dkrClient.Containers.ListContainersAsync(new ContainersListParameters
     {
         All = true,
         Filters = new Dictionary <string, IDictionary <string, bool> >
         {
             { "name", new Dictionary <string, bool>
               {
                   { name, true }
               } }
         }
     }));
 }
 /// <summary>
 /// Gets any image objects from the client by matching repository:tag.
 /// </summary>
 /// <param name="repoTag">The image repository:tag to look for.</param>
 /// <param name="dkrClient">The client to request the image from.</param>
 /// <returns>The image objects matching the repository:tag.</returns>
 internal static async Task <IList <ImagesListResponse> > GetImagesByRepoTag(string repoTag, DotNet.DockerClient dkrClient)
 {
     return((await dkrClient.Images.ListImagesAsync(new ImagesListParameters()
     {
         All = true
     }))
            .Where(i => i.RepoTags.Any(rt => repoTag.Split('/').Last().Contains(":") ? rt == repoTag : rt == (repoTag + ":latest"))).ToList());
 }
 /// <summary>
 /// Gets a single container object from the client by id or name.
 /// </summary>
 /// <param name="id">The container identifier to retrieve.</param>
 /// <param name="dkrClient">The client to request the container from.</param>
 /// <returns>The single container object matching the id.</returns>
 internal static async Task <IList <ContainerListResponse> > GetContainersByIdOrName(string id, DotNet.DockerClient dkrClient)
 {
     return((await GetContainersByName(id, dkrClient)).Where(c => c.Names.Contains($"/{id}")).Concat(await GetContainersById(id, dkrClient)).ToList());
 }
 internal static Task <IList <NetworkListResponse> > GetNetworksById(string id, DotNet.DockerClient dkrClient)
 {
     return(dkrClient.Networks.ListNetworksAsync(new NetworksListParameters
     {
         Filters = new Dictionary <string, IDictionary <string, bool> >
         {
             { "id", new Dictionary <string, bool>
               {
                   { id, true }
               } }
         }
     }));
 }