0

I have a Dockerfile that uses an ubuntu base image and installs a bunch of dependencies with apt-get and dpkg. Then it copies some javascript files and runs a node app. The node app spawns a child process and executes xvfb-run selenium-standalone start.

If I build the docker image with --no-cache and run it using docker run -i -t <image id> my app starts and connects to the selenium server immediately. If I kill the container using CTRL-C or docker stop <container id> and then run the exact same docker run command as above, my app starts as normal, but cannot connect to the selenium server. If I leave it alone, five minutes later, it will connect properly on its own. It behaves this way every time I run docker run until I do a clean image build.

Changing a node source file and rebuilding mostly from cache does not alter this behavior. I've repeated the process several times and it's always the same.

I can't figure out how the behavior can change from one docker run to the next, if the same image is used. Where is the shared state?

Log when working:

gulp run
22:42:31.541 INFO - Launching a standalone Selenium Server
Setting system property webdriver.chrome.driver to /usr/lib/node_modules/selenium-standalone/.selenium/chromedriver/2.16-x64-chromedriver
22:42:31.579 INFO - Java: Oracle Corporation 24.79-b02
22:42:31.579 INFO - OS: Linux 3.18.5-tinycore64 amd64
22:42:31.594 INFO - v2.46.0, with Core v2.46.0. Built from revision 87c69e2
22:42:31.676 INFO - Driver provider org.openqa.selenium.ie.InternetExplorerDriver registration is skipped: registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match the current platform LINUX
22:42:31.676 INFO - Driver class not found: com.opera.core.systems.OperaDriver
22:42:31.677 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
[22:42:31] Using gulpfile /opt/app/gulpfile.js
[22:42:31] Starting 'run'...
[22:42:31] Finished 'run' after 1.29 ms
Started App.
22:42:31.764 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
22:42:31.764 INFO - Selenium Server is up and running
Selenium started
2015-08-19T22:42:32.445Z Starting app on port: 8000

Logs when not working are exactly the same except missing the RemoteWebDriver, 'Selenium Server is up and running', and 'Selenium started.' lines.

cava23
  • 477
  • 1
  • 8
  • 16
  • do you have the same server between the runs? Could it be the culprit? – Mykola Gurov Aug 19 '15 at 20:32
  • you could running your container with the [`--read-only`](https://docs.docker.com/reference/commandline/run/) flag – Thomasleveil Aug 19 '15 at 21:29
  • The server should die with the container, right? It's accessed using localhost, which should be the container. – cava23 Aug 19 '15 at 22:26
  • @Thomasleveil The application writes to the filesystem, so it won't run in read-only mode. – cava23 Aug 19 '15 at 22:27
  • @cava23 you have logs ? did you try get stdout/stderr logs with `docker logs`. Also the state may be in your selenium server. – Rico Aug 19 '15 at 22:43
  • @Rico I added the log output to the post. The selenium server is running within the container, so a new one should be created each time docker run is executed. – cava23 Aug 19 '15 at 22:56
  • It looks like it's trying to connect to http://127.0.0.1:4444/wd/hub so what may be happening is that port `4444` may be bound by the the first run of your docker container. After your first `docker run` and then exit, can you run `lsof -i:4444` ? and see if the port is taken by process on the host machine ? – Rico Aug 19 '15 at 23:00
  • @Rico No open files listed with port 4444 on host machine. For the docker container to connect to a resource on the host machine, it would have to either use the gateway or the boot2docker ip. 127.0.0.1 or localhost will be limited to the container (unless an alias is configured somewhere?). – cava23 Aug 20 '15 at 13:15
  • @Rico If I run lsof -i:4444 on the container I see the selenium server file handle. When it fails to connect (2nd run), there is no file handle for a couple minutes. As soon as I see one, it starts up and connects and all is well. So, it looks like the selenium server is not starting right away every time. I just can't figure out why it works every time on a clean image build! – cava23 Aug 20 '15 at 13:23
  • There probably there's pid file or something inside your container that is saving state for your selenium client and maybe after 5 minutes your selenium client realizes that it's not running and restarts – Rico Aug 21 '15 at 03:05

1 Answers1

0

Try removing the container instead of just stopping it:

docker stop <container id>
docker rm <container id>
Rico
  • 58,485
  • 12
  • 111
  • 141
Chris
  • 1,692
  • 2
  • 17
  • 21
  • Didn't seem to make a difference. This behavior has been duplicated on another machine as well. – cava23 Aug 19 '15 at 22:23