Пример #1
0
        public DockerContainer Build()
        {
            var container = _client.Containers.ListContainersAsync(new ContainersListParameters {
                All = true
            }).ConfigureAwait(false).GetAwaiter().GetResult()
                            .FirstOrDefault(x => x.Names.Any(n => n.Equals("/" + Name, StringComparison.OrdinalIgnoreCase)));

            bool isRunning = container?.State == "running";

            if (container != null && !RemovePreviousContainer)
            {
                return(new DockerContainer(_client, container.ID, isRunning));
            }

            if (container != null && RemovePreviousContainer)
            {
                using var oldContainer = new DockerContainer(_client, container.ID, isRunning);
                oldContainer.Stop();
                oldContainer.Remove();
            }

            _client.Images.CreateImageAsync(new ImagesCreateParameters {
                FromImage = FromImage, Tag = Tag
            }, null, new Progress <JSONMessage>()).ConfigureAwait(false).GetAwaiter().GetResult();

            var newContainer = _client.Containers.CreateContainerAsync(new CreateContainerParameters
            {
                Image        = $"{FromImage}:{Tag ?? "latest"}",
                Name         = Name,
                Env          = Env,
                ExposedPorts = new Dictionary <string, EmptyStruct> {
                    { ExposedPort, new EmptyStruct() }
                },
                Cmd        = Cmd,
                HostConfig = new HostConfig
                {
                    PortBindings = new Dictionary <string, IList <PortBinding> >
                    {
                        { ExposedPort, new List <PortBinding> {
                              new PortBinding {
                                  HostIP = "localhost", HostPort = HostPort
                              }
                          } }
                    }
                }
            }).ConfigureAwait(false).GetAwaiter().GetResult();

            return(new DockerContainer(_client, newContainer.ID, isRunning: false));
        }
Пример #2
0
        public bool Start(bool fromScratch = false)
        {
            _container = new DockerContainerBuilder(new DockerContainerBuilderOptions
            {
                FromImage               = "cockroachdb/cockroach",
                Tag                     = "latest",
                Name                    = "cockroachdb-evolve",
                ExposedPort             = $"{ExposedPort}/tcp",
                HostPort                = HostPort,
                RemovePreviousContainer = fromScratch,
                Cmd                     = new[] { "start", "--insecure" }
            }).Build();

            return(_container.Start());
        }
Пример #3
0
        public bool Start(bool fromScratch = false)
        {
            _container = new DockerContainerBuilder(new DockerContainerBuilderOptions
            {
                FromImage               = "mariadb",
                Tag                     = "latest",
                Name                    = "mariadb-evolve",
                Env                     = new[] { $"MYSQL_ROOT_PASSWORD={DbPwd}", $"MYSQL_DATABASE={DbName}" },
                ExposedPort             = $"{ExposedPort}/tcp",
                HostPort                = HostPort,
                RemovePreviousContainer = fromScratch
            }).Build();

            return(_container.Start());
        }
Пример #4
0
        public bool Start(bool fromScratch = false)
        {
            _container = new DockerContainerBuilder(new DockerContainerBuilderOptions
            {
                FromImage               = "postgres",
                Tag                     = "alpine",
                Name                    = "postgres-evolve",
                Env                     = new[] { $"POSTGRES_PASSWORD={DbPwd}", $"POSTGRES_DB={DbName}" },
                ExposedPort             = $"{ExposedPort}/tcp",
                HostPort                = HostPort,
                RemovePreviousContainer = fromScratch
            }).Build();

            return(_container.Start());
        }
Пример #5
0
        public bool Start(bool fromScratch = false)
        {
            _container = new DockerContainerBuilder(new DockerContainerBuilderOptions
            {
                FromImage               = "mcr.microsoft.com/mssql/server",
                Tag                     = "latest",
                Name                    = "mssql-evolve",
                Env                     = new[] { $"ACCEPT_EULA=Y", $"SA_PASSWORD={DbPwd}" },
                ExposedPort             = $"{ExposedPort}/tcp",
                HostPort                = HostPort,
                RemovePreviousContainer = fromScratch
            }).Build();

            return(_container.Start());
        }
Пример #6
0
        public bool Start(bool fromScratch = false)
        {
            _container = new DockerContainerBuilder(new DockerContainerBuilderOptions
            {
                FromImage               = "cassandra",
                Tag                     = "latest",
                Name                    = "cassandra-evolve",
                Env                     = new[] { $"CASSANDRA_CLUSTER_NAME={ClusterName}", $"CASSANDRA_DC={DataCenter}", "CASSANDRA_RACK=rack1" },
                ExposedPort             = $"{ExposedPort}/tcp",
                HostPort                = HostPort,
                RemovePreviousContainer = fromScratch
            }).Build();

            return(_container.Start());
        }