Browse Source

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
pull/259/head
David Fowler 6 years ago
committed by GitHub
parent
commit
4f73950de5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/Microsoft.Tye.Hosting/DockerRunner.cs
  2. 1
      test/E2ETest/TyeRunTests.cs

15
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;

1
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"));

Loading…
Cancel
Save