コード例 #1
0
        public static INetworkService SetupTestNetwork(String networkName)
        {
            DockerEnginePlatform engineType = DockerHelper.GetDockerEnginePlatform();

            if (engineType == DockerEnginePlatform.Windows)
            {
                var docker  = DockerHelper.GetDockerHost();
                var network = docker.GetNetworks().Where(nw => nw.Name == networkName).SingleOrDefault();
                if (network == null)
                {
                    network = docker.CreateNetwork(networkName,
                                                   new NetworkCreateParams
                    {
                        Driver = "nat",
                    });
                }

                return(network);
            }

            if (engineType == DockerEnginePlatform.Linux)
            {
                // Build a network
                NetworkBuilder networkService = new Builder().UseNetwork(networkName).ReuseIfExist();

                return(networkService.Build());
            }

            return(null);
        }
コード例 #2
0
        public static DockerEnginePlatform GetDockerEnginePlatform()
        {
            IHostService docker = DockerHelper.GetDockerHost();

            if (docker.Host.IsLinuxEngine())
            {
                return(DockerEnginePlatform.Linux);
            }

            if (docker.Host.IsWindowsEngine())
            {
                return(DockerEnginePlatform.Windows);
            }
            throw new Exception("Unknown Engine Type");
        }