aerokube / images

Browser images for Selenoid and Moon 1.x
https://aerokube.com/images/latest/
Apache License 2.0
170 stars 127 forks source link

Standalone Chrome in Docker #27

Closed bonigarcia closed 6 years ago

bonigarcia commented 6 years ago

I'm trying to use the Selenoid Docker images for Chrome directly, without using the Selenoid Hub. To that, I simply start a Chrome in Docker with the following command:

docker run --rm -p 4444:4444 selenoid/vnc:chrome_64.0

Then, I have a JUnit 4 test as follows:

import static org.junit.Assert.assertTrue;
import static org.openqa.selenium.remote.DesiredCapabilities.chrome;

import java.net.MalformedURLException;
import java.net.URL;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;

public class RemoteTest {

    private WebDriver driver;

    @Before
    public void setup() throws MalformedURLException {
        driver = new RemoteWebDriver(new URL("http://localhost:4444/"),
                chrome());
    }

    @After
    public void teardown() {
        if (driver != null) {
            driver.quit();
        }
    }

    @Test
    public void test() {
        driver.get("https://en.wikipedia.org/wiki/Main_Page");
        assertTrue(
                driver.getTitle().equals("Wikipedia, the free encyclopedia"));
    }

}

Unfortunately it does not work. The container logs are the following:

 --- x11vnc loop: 1 ---

Starting ChromeDriver 2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881) on port 4444
All remote connections are allowed. Use a whitelist instead!
 --- x11vnc loop: waiting for: 34

PORT=5900
[1517227546.481][INFO]: COMMAND InitSession {
   "capabilities": {
      "desiredCapabilities": {
         "browserName": "chrome",
         "platform": "ANY",
         "version": ""
      },
      "firstMatch": [ {
         "browserName": "chrome"
      } ]
   },
   "desiredCapabilities": {
      "browserName": "chrome",
      "platform": "ANY",
      "version": ""
   }
}
[1517227546.481][INFO]: Populating Preferences file: {
   "alternate_error_pages": {
      "enabled": false
   },
   "autofill": {
      "enabled": false
   },
   "browser": {
      "check_default_browser": false
   },
   "distribution": {
      "import_bookmarks": false,
      "import_history": false,
      "import_search_engine": false,
      "make_chrome_default_for_user": false,
      "skip_first_run_ui": true
   },
   "dns_prefetching": {
      "enabled": false
   },
   "profile": {
      "content_settings": {
         "pattern_pairs": {
            "https://*,*": {
               "media-stream": {
                  "audio": "Default",
                  "video": "Default"
               }
            }
         }
      },
      "default_content_setting_values": {
         "geolocation": 1
      },
      "default_content_settings": {
         "geolocation": 1,
         "mouselock": 1,
         "notifications": 1,
         "popups": 1,
         "ppapi-broker": 1
      },
      "password_manager_enabled": false
   },
   "safebrowsing": {
      "enabled": false
   },
   "search": {
      "suggest_enabled": false
   },
   "translate": {
      "enabled": false
   }
}
[1517227546.481][INFO]: Populating Local State file: {
   "background_mode": {
      "enabled": false
   },
   "ssl": {
      "rev_checking": {
         "enabled": false
      }
   }
}
[1517227546.482][INFO]: Launching chrome: /usr/bin/google-chrome --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-logging --force-fieldtrials=SiteIsolationExtensions/Control --ignore-certificate-errors --load-extension=/tmp/.org.chromium.Chromium.IznbZ4/internal --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12627 --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.org.chromium.Chromium.ptNi6n data:,
[1517227546.482][DEBUG]: DevTools request: http://localhost:12627/json/version
Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted
[1517227546.617][DEBUG]: DevTools request failed
[1517227546.667][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227546.668][DEBUG]: DevTools request failed
[1517227546.718][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227546.719][DEBUG]: DevTools request failed
[1517227546.769][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227546.771][DEBUG]: DevTools request failed
[1517227546.821][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227546.822][DEBUG]: DevTools request failed
[1517227546.872][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227546.873][DEBUG]: DevTools request failed
[1517227546.924][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227546.925][DEBUG]: DevTools request failed
[1517227546.975][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227546.976][DEBUG]: DevTools request failed
[1517227547.026][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227547.027][DEBUG]: DevTools request failed
[1517227547.077][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227547.078][DEBUG]: DevTools request failed
[1517227547.128][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227547.129][DEBUG]: DevTools request failed
[1517227547.179][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227547.181][DEBUG]: DevTools request failed
[1517227547.231][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227547.232][DEBUG]: DevTools request failed
[1517227547.282][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227547.283][DEBUG]: DevTools request failed
[1517227547.333][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227547.335][DEBUG]: DevTools request failed
[1517227547.385][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227547.386][DEBUG]: DevTools request failed
[1517227547.437][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227547.438][DEBUG]: DevTools request failed
[1517227547.488][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227547.489][DEBUG]: DevTools request failed
[1517227547.540][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227547.540][DEBUG]: DevTools request failed
[1517227547.590][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227547.590][DEBUG]: DevTools request failed
[1517227547.641][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227547.641][DEBUG]: DevTools request failed
[1517227547.691][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227547.692][DEBUG]: DevTools request failed
[1517227547.742][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227547.743][DEBUG]: DevTools request failed
[1517227547.793][DEBUG]: DevTools request: http://localhost:12627/json/version
[1517227547.795][DEBUG]: DevTools request failed

It continues stalled and I have to stop manually the container. I tried to solve for similar issues but I did not find the solution yet.

Any idea about this?

Thank you very much in advance.

bonigarcia commented 6 years ago

I just found the solution for my problem. Simply changing the way in which the container is started:

docker run --rm --cap-add=SYS_ADMIN -p 4444:4444 selenoid/vnc:chrome_64.0

Sorry for the noise.

vania-pooh commented 6 years ago

:)

bonigarcia commented 6 years ago

I'm opening this issue again since I have an additional problem. The command before actually works:

docker run --rm --cap-add=SYS_ADMIN -p 4444:4444 selenoid/vnc:chrome_64.0

... but the problem is that I cannot stop the container gracefully. Using Ctrl-C is not working, and using docker stop gets stalled for a while until it is finally closed.

Any idea? Thanks again!

vania-pooh commented 6 years ago

Selenoid is removing container with --force flag. Also to use Ctrl-C you have to launch container in interactive mode:

docker run -it ....
bonigarcia commented 6 years ago

Yes, using the --force flag did the trick, thank you @vania-pooh.