无法连接Chrome

时间:2019-02-07 06:48:57

标签: google-chrome docker

我正在开发,需要与google chrome进行一些交互。我在Docker容器中运行我的应用程序。当它在docker外部时,我可以连接到chrome浏览器,但是当它在docker内部时,我会收到类似

的错误
  ChromeLauncher:error connect ECONNREFUSED 127.0.0.1:33715 +2ms
  ChromeLauncher Waiting for browser. +0ms
  ChromeLauncher Waiting for browser... +0ms
  ChromeLauncher Waiting for browser..... +511ms
  ChromeLauncher Waiting for browser....... +502ms
  ChromeLauncher Waiting for browser......... +503ms
  ChromeLauncher Waiting for browser........... +502ms
  ChromeLauncher Waiting for browser............. +502ms
  ChromeLauncher Waiting for browser............... +502ms
  ChromeLauncher Waiting for browser................. +503ms
  ChromeLauncher Waiting for browser................... +502ms
  ChromeLauncher Waiting for browser..................... +502ms
  ChromeLauncher Waiting for browser....................... +502ms
  ChromeLauncher Waiting for browser......................... +501ms
  ChromeLauncher Waiting for browser........................... +502ms
  ChromeLauncher Waiting for browser............................. +503ms
  ChromeLauncher Waiting for browser............................... +502ms
  ChromeLauncher Waiting for browser................................. +502ms
  ChromeLauncher Waiting for browser................................... +500ms
  ChromeLauncher Waiting for browser..................................... +502ms
  ChromeLauncher Waiting for browser....................................... +501ms
  ChromeLauncher Waiting for browser......................................... +501ms
  ChromeLauncher Waiting for browser........................................... +502ms
  ChromeLauncher Waiting for browser............................................. +501ms
  ChromeLauncher Waiting for browser............................................... +502ms
  ChromeLauncher Waiting for browser................................................. +503ms
  ChromeLauncher Waiting for browser................................................... +502ms
  ChromeLauncher Waiting for browser..................................................... +502ms
  ChromeLauncher Waiting for browser....................................................... +502ms
  ChromeLauncher Waiting for browser......................................................... +501ms
  ChromeLauncher Waiting for browser........................................................... +502ms
  ChromeLauncher Waiting for browser............................................................. +502ms
  ChromeLauncher Waiting for browser............................................................... +503ms
  ChromeLauncher Waiting for browser................................................................. +502ms
  ChromeLauncher Waiting for browser................................................................... +502ms
  ChromeLauncher Waiting for browser..................................................................... +502ms
  ChromeLauncher Waiting for browser....................................................................... +502ms
  ChromeLauncher Waiting for browser......................................................................... +502ms
  ChromeLauncher Waiting for browser........................................................................... +502ms
  ChromeLauncher Waiting for browser............................................................................. +502ms
  ChromeLauncher Waiting for browser............................................................................... +502ms
  ChromeLauncher Waiting for browser................................................................................. +503ms
  ChromeLauncher Waiting for browser................................................................................... +502ms
  ChromeLauncher Waiting for browser..................................................................................... +502ms
  ChromeLauncher Waiting for browser....................................................................................... +503ms
  ChromeLauncher Waiting for browser......................................................................................... +502ms
  ChromeLauncher Waiting for browser........................................................................................... +502ms
  ChromeLauncher Waiting for browser............................................................................................. +501ms
  ChromeLauncher Waiting for browser............................................................................................... +502ms
  ChromeLauncher Waiting for browser................................................................................................. +502ms
  ChromeLauncher Waiting for browser................................................................................................... +502ms
  ChromeLauncher Waiting for browser..................................................................................................... +502ms
  ChromeLauncher Waiting for browser....................................................................................................... +502ms
  ChromeLauncher:error connect ECONNREFUSED 127.0.0.1:33715 +2ms
  ChromeLauncher:error Logging contents of /tmp/lighthouse.ZztambY/chrome-err.log +1ms
  ChromeLauncher:error [0207/061816.421061:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
  ChromeLauncher:error  +0ms
Unable to connect to Chrome

1 个答案:

答案 0 :(得分:0)

启动应用容器时,可以在MandatoryFields.Task命令中使用--add-host标志:

 public void CaptureImage(int request){
    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    cameraIntent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
    cameraIntent.putExtra("android.intent.extras.LENS_FACING_FRONT", 1);
    cameraIntent.putExtra("android.intent.extra.USE_FRONT_CAMERA", true);
    startActivityForResult(cameraIntent, request);
}

然后,您可以通过docker run主机名访问本地运行的chrome实例。当然,所有这些都要求您使用的端口实际上是开放的(我认为是因为应用程序在容器外部运行)。