示例#1
0
 public void Start(ContainerBase container)
 {
     _dockerClient.Containers.StartContainerAsync(container.Id, new ContainerStartParameters())
     .ConfigureAwait(false)
     .GetAwaiter()
     .GetResult();
 }
示例#2
0
 public void Remove(ContainerBase container)
 {
     _dockerClient.Containers.RemoveContainerAsync(container.Id, new ContainerRemoveParameters {
         Force = true
     })
     .ConfigureAwait(false)
     .GetAwaiter()
     .GetResult();
 }
示例#3
0
        public string Run(ContainerBase container)
        {
            var portBindings = new Dictionary <string, IList <PortBinding> >();

            container.MappedPorts.ForEach(portMap =>
            {
                portBindings.Add(portMap.Item1, new List <PortBinding> {
                    new PortBinding {
                        HostIP = "localhost", HostPort = portMap.Item2
                    }
                });
            });

            var response = _dockerClient.Containers.CreateContainerAsync(new CreateContainerParameters
            {
                Name         = container.Name,
                Image        = $"{container.Image}:{container.Tag}",
                Env          = container.Env.Select(t => $"{t.Item1}={t.Item2}").ToList(),
                Cmd          = container.Cmd,
                ExposedPorts = container.ExposedPorts.ToDictionary(x => x, x => default(EmptyStruct)),
                HostConfig   = new HostConfig
                {
                    PortBindings    = portBindings,
                    PublishAllPorts = true
                }
            })
                           .ConfigureAwait(false)
                           .GetAwaiter()
                           .GetResult();

            _dockerClient.Containers.StartContainerAsync(response.ID, null)
            .ConfigureAwait(false)
            .GetAwaiter()
            .GetResult();

            return(response.ID);
        }