From 4f73950de52831e655463851ada7ae366f95b28c Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 29 Mar 2020 22:36:44 -0700 Subject: [PATCH] Work around host.docker.internal not working on linux (#254) - Use the machine ip instead of host.docker.internal PS: Will look into overwriting the host file in the container but its a tad bit hacky. Fixes #176 --- src/Microsoft.Tye.Hosting/DockerRunner.cs | 15 ++++++++++++++- test/E2ETest/TyeRunTests.cs | 1 - 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Tye.Hosting/DockerRunner.cs b/src/Microsoft.Tye.Hosting/DockerRunner.cs index 553ac96c..7e0ebaaf 100644 --- a/src/Microsoft.Tye.Hosting/DockerRunner.cs +++ b/src/Microsoft.Tye.Hosting/DockerRunner.cs @@ -6,6 +6,8 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; @@ -79,6 +81,17 @@ namespace Microsoft.Tye.Hosting var environmentArguments = ""; var volumes = ""; var workingDirectory = docker.WorkingDirectory != null ? $"-w {docker.WorkingDirectory}" : ""; + var hostname = "host.docker.internal"; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + // See: https://github.com/docker/for-linux/issues/264 + // + // host.docker.internal is making it's way into linux docker but doesn't work yet + // instead we use the machine IP + var addresses = await Dns.GetHostAddressesAsync(Dns.GetHostName()); + hostname = addresses[0].ToString(); + } // This is .NET specific var userSecretStore = GetUserSecretsPathFromSecrets(); @@ -142,7 +155,7 @@ namespace Microsoft.Tye.Hosting // // The way we do proxying here doesn't really work for multi-container scenarios on linux // without some more setup. - application.PopulateEnvironment(service, (key, value) => environment[key] = value, "host.docker.internal"); + application.PopulateEnvironment(service, (key, value) => environment[key] = value, hostname); environment["APP_INSTANCE"] = replica; diff --git a/test/E2ETest/TyeRunTests.cs b/test/E2ETest/TyeRunTests.cs index 5f90cccb..1a903ff6 100644 --- a/test/E2ETest/TyeRunTests.cs +++ b/test/E2ETest/TyeRunTests.cs @@ -300,7 +300,6 @@ namespace E2ETest [ConditionalFact] [SkipIfDockerNotRunning] - [SkipOnLinux] public async Task FrontendBackendRunTestWithDocker() { var projectDirectory = new DirectoryInfo(Path.Combine(TestHelpers.GetSolutionRootDirectory("tye"), "samples", "frontend-backend"));