public void UseNetworkAndStaticIpv4ShallWork() { string container = null; try { var cmd = _docker.Run("postgres:9.6-alpine", new ContainerCreateParams { PortMappings = new[] { "40001:5432" }, Environment = new[] { "POSTGRES_PASSWORD=mysecretpassword" }, Network = "mynetwork", Ipv4 = "1.1.1.1" }, _certificates); Assert.IsTrue(cmd.Success); container = cmd.Data; var insp = _docker.InspectContainer(container, _certificates); Assert.IsTrue(insp.Success); var ip = insp.Data.NetworkSettings.IPAddress; Assert.AreEqual("1.1.1.1", ip); } finally { if (null != container) { _docker.RemoveContainer(container, true, true); } } }
public void UseNetworkAndStaticIpv4ShallWork() { string container = null; string id = null; try { var created = _docker.NetworkCreate("unit-test-nw", new NetworkCreateParams { Subnet = new [] { "10.18.0.0/16" } }, _certificates); Assert.IsTrue(created.Success); id = created.Data[0]; var cmd = _docker.Run("postgres:9.6-alpine", new ContainerCreateParams { PortMappings = new[] { "40001:5432" }, Environment = new[] { "POSTGRES_PASSWORD=mysecretpassword" }, Network = "unit-test-nw", Ipv4 = "10.18.0.22" }, _certificates); Assert.IsTrue(cmd.Success); container = cmd.Data; var insp = _docker.InspectContainer(container, _certificates); Assert.IsTrue(insp.Success); var ip = insp.Data.NetworkSettings.Networks["unit-test-nw"].IPAddress; Assert.AreEqual("10.18.0.22", ip); } finally { if (null != container) { _docker.RemoveContainer(container, true, true); } if (null != id) { _docker.NetworkRm(network: id); } } }
public void ConnectAndDisconnectContainerToNetworkShallWork() { string id = null; string container = null; try { var cmd = _docker.Run("postgres:9.6-alpine", new ContainerCreateParams { PortMappings = new[] { "40001:5432" }, Environment = new[] { "POSTGRES_PASSWORD=mysecretpassword" } }, _certificates); Assert.IsTrue(cmd.Success); container = cmd.Data; var created = _docker.NetworkCreate("unit-test-nw"); if (created.Success) { id = created.Data[0]; } Assert.IsNotNull(id); _docker.NetworkConnect(container, id); var inspect = _docker.NetworkInspect(network: id); Assert.IsTrue(inspect.Success); Assert.IsTrue(inspect.Data.Containers.ContainsKey(container)); var disconnect = _docker.NetworkDisconnect(container, id, true /*force*/); Assert.IsTrue(disconnect.Success); inspect = _docker.NetworkInspect(network: id); Assert.IsFalse(inspect.Data.Containers.ContainsKey(container)); } finally { if (null != container) { _docker.RemoveContainer(container, true, true); } if (null == id) { var networks = _docker.NetworkLs(_certificates); if (networks.Success) { id = networks.Data.Where(x => x.Name == "unit-test-nw").Select(x => x.Id).FirstOrDefault(); } } if (null != id) { _docker.NetworkRm(network: id); } } }
public void LogsFromContaierWhenNotFollowModeShallExitByItself() { string id = null; try { var cmd = _docker.Run("postgres:9.6-alpine", new ContainerCreateParams { PortMappings = new[] { "40001:5432" }, Environment = new[] { "POSTGRES_PASSWORD=mysecretpassword" } }, _certificates); id = cmd.Data; var config = _docker.InspectContainer(id, _certificates); var endpoint = config.Data.NetworkSettings.Ports.ToHostPort("5432/tcp", _docker); endpoint.WaitForPort(10000 /*10s*/); using (var logs = _docker.Logs(id)) { while (!logs.IsFinished) { var line = logs.TryRead(5000); if (null == line) { Assert.AreEqual(true, logs.IsFinished, "Since null line, the process shall been shutdown"); break; } Debug.WriteLine(line); } Assert.AreEqual(true, logs.IsFinished); Assert.AreEqual(true, logs.IsSuccess); } } finally { if (null != id) { _docker.RemoveContainer(id, true, true, null, _certificates); } } }
public void StartEventShallBeEmittedWhenContainerStart() { var host = Fd.Native(); string id = null; try { using (var events = host.Events()) { var cmd = _docker.Run("postgres:9.6-alpine", new ContainerCreateParams { PortMappings = new[] { "40001:5432" }, Environment = new[] { "POSTGRES_PASSWORD=mysecretpassword" } }, _certificates); id = cmd.Data; FdEvent e = null; while ((e = events.TryRead(3000)) != null) { if (e.Type == EventType.Container && e.Action == EventAction.Start) { break; } } Assert.IsNotNull(e); } } finally { if (null != id) { _docker.RemoveContainer(id, true, true, null, _certificates); } } }
public void RunWithoutArgumentShallSucceed() { string id = null; try { var cmd = _docker.Run("nginx:1.13.6-alpine", null, _certificates); IsTrue(cmd.Success); id = cmd.Data; IsTrue(!string.IsNullOrWhiteSpace(id)); AreEqual(64, id.Length); } finally { if (null != id) { _docker.RemoveContainer(id, true, true, null, _certificates); } } }