Ejemplo n.º 1
0
        public void Pulls_runs_stops_image()
        {
            var client = new DockerClient();

            client.PullImage("ubuntu");

            var containerName = "lcldckr-test-container";

            var id = client.RunImage("ubuntu", "latest", new RunArguments {
                Name = containerName, Interactive = true
            });

            Assert.NotNull(id);

            var runningContainer = client
                                   .Ps(true, new[] { new NameFilter(containerName) })
                                   .SingleOrDefault();

            Assert.NotNull(runningContainer);

            Assert.Equal(containerName, runningContainer.Names.Single());

            Assert.Equal(id.Substring(0, 12), runningContainer.ContainerId);

            id = client.StopContainer(containerName);
            Assert.NotNull(id);

            id = client.RemoveContainer(containerName);
            Assert.NotNull(id);
        }
Ejemplo n.º 2
0
 private string getContainer(string image)
 {
     try
     {
         if (!containers.ContainsKey(image))
         {
             try
             {
                 docker.PullImage(image).Wait();
             }
             catch (Exception ee)
             {
                 logger.LogWarning($"Warning: pull {image} failed");
             }
             var c = docker.CreateContainer(image, "/app", new string[] {
                 $"{workDir}/data/pulls:/app/wn_pulls",
                 $"{workDir}/data/out:/app/wn_out",
                 $"{workDir}/data/app:/app"
             });
             c.Wait();
             logger.LogInformation($"container {c.Result}({image}) created.");
             containers[image] = c.Result;
         }
         return(containers[image]);
     }
     catch (Exception e)
     {
         return(null);
     }
 }
Ejemplo n.º 3
0
        public void Force_remove()
        {
            var client = new DockerClient();

            client.PullImage("ubuntu");

            var containerName = "lcldckr-test-container";

            var id = client.RunImage("ubuntu", "latest", new RunArguments {
                Name = containerName, Interactive = true
            });

            Assert.NotNull(id);

            id = client.RemoveContainer(containerName, force: true);
            Assert.NotNull(id);
        }
Ejemplo n.º 4
0
        public ImpalaTestFixture()
        {
            var client = new DockerClient();

            client.PullImage("andreysabitov/impala-kudu");
            client.RunOrReplace("andreysabitov/impala-kudu", "latest", new RunArguments
            {
                Name         = "impala-test",
                HostName     = "impala-test",
                PortMappings = new Dictionary <string, string>
                {
                    { "21000", "21000" }
                }
            });

            IPAddress ip = IPAddress.Parse("127.0.0.1");

            // Wait for impala here so we dont scew test times
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            while (stopWatch.Elapsed < TimeSpan.FromMinutes(5))
            {
                try
                {
                    using (var tcpClient = new TcpClient())
                    {
                        tcpClient.Connect(ip, 21000);
                        break;
                    }
                }
                catch (Exception e)
                {
                    Thread.Sleep(TimeSpan.FromMilliseconds(500));
                }
            }

            ImpalaIp = ip;
        }