Docker "Failed to open TCP connection to 127.0.0.1:4444" when running selenium/capybara test in container - ruby

I have some Selenium Webdriver/Capybara automation setup in a ruby app. Along with this in a VirtualBox VM using Linux I have a docker container for Selenium grid docker run -d -p 4444:4444 --name selenium-hub -e GRID_TIMEOUT=120000 selenium/hub:2.53.0 and a firefox node docker run -d --link selenium-hub:hub selenium/node-firefox:2.53.0. After adding a DNS entry to docker_opts on the VM, in my host machine if I run my Selenium test (which uses the grid on my VM) everything works fine.
After this I setup my automation code in a ruby container on my vm along side the grid and containers. The container builds just fine. I am also able to attach to it without issue and all my code is there as expected. from the terminal in my automation container if attempt to run a spec ex. rspec spec/some_spec.rb I will get a connection refused error
"Failed to open TCP connection to 127.0.0.1:4444 (Connection refused - connect(2) for \"127.0.0.1\" port 4444)"
of the 18 results googling up this issue the only thing I saw that seemed actionable mentioned creating a bridge, which I don't really understand. Any suggestions on how to correct this would be greatly appreciated.

It's not easy to say without seeing your specs but I'm guessing you connect to selenium on 127.0.0.1:4444 in your tests?
If so you should now connect to it on hub:4444 as that is the name which will resolve to the IP of your selenium hub container.

Related

Cannot forward ports when running Linux container on Windows10 as a host

I'm new using Docker. I have been trying to deploy a Linux container (with Windows as a host) with a Google Cloud image inside using Docker. I'm able to do everything well, at the end the server is running perfectly, but when I want to check the server, using the localhost in the browser, I got a blank page with:
Blank page
This is the Dockerfile:
FROM google/cloud-sdk
ENV PATH /usr/lib/google-cloud-sdk/bin:$PATH
WORKDIR docker_folder
COPY local_folder/ .
RUN pwd
EXPOSE 8080
CMD ["java_dev_appserver.sh", "."]
This is the command I'm using to build my image (in the CMD):
docker build --tag serverdeploy .
This is the command I'm using to run my container
docker run -p 8080:8080 serverdeploy
This is the stack trace that I got when I run the server
where I know that I running the server
I did some research and looks like Docker had a problem with the ports when you use a Linux container in Windows (Not sure if it's already solved or not). I've already tried all the possible solutions that I found out there (even trying to replace 'localhost' by all the ip's that I get when I run ipconfig on the cmd) but I still get the same error.
And, as last hope, I need your help to understand what I'm doing wrong, or if I missing something
You are running your service bind to localhost - that means no remote connections are accepted (as well as binding to 127.0.0.1. And for your container the host is a remote connection.
Change binding to 0.0.0.0 (which I guess is default) and enjoy.
Btw sharing your java_dev_appserver.sh would be helpful for answering the question.

Docker on Win10 - is it possible to have multiple terminals?

I am new to Docker - installed DockerToolbox on Win10. And managed to run some basic docker examples. But I cannot seem to figure out how to access same container from multiple command line windows.
Quick online search suggested finding container ID (e.g. 2c7e29b9b666) via
docker ps
then running (I presume in new command window)
docker exec -it 2c7e29b9b666 bash
but that does not work in Win10.
Error message received is:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Edit: in the first window I started docker machine via:
docker-machine create --driver virtualbox tombox
and I can see 'tombox' in second window if I do:
docker-machine ls
Do I need to somehow reference 'tombox' when running docker commands in second window?

How to connect to a running docker image on a Mac?

I am following this tutorial on using docker images, and I am at the stage to run the example docker image like follows:
docker run -p 4000:80 friendlyhello
On the command line it seems ok:
>docker run -p 4000:80 friendlyhello
* Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
but when I try to open the page http://localhost:4000 on a web browser, it seems to be unable to connect (Safari and Firefox). On Firefox the error message is
Unable to connect
Firefox can't establish a connection to the server at localhost:4000.
The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer's network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.
I also checked the file /etc/hosts and it contains the following entry
127.0.0.1 localhost
So what could be the problem?
I found this solution and tried the following command:
docker run -p 127.0.0.1:4000:80 friendlyhello
which still leads to the same problem. I also tried to open
`http://localhost:80`
again without success.

Connecting with JMX using Docker for Mac

I'm struggling with setting up a JMX connection to Tomcat running in a Docker container using Docker for Mac.
I think I understand the basics, and have a setenv.sh in the tomcat/bin directory looking like this:
CATALINA_OPTS="-Dcom.sun.management.jmxremote=true\
-Dcom.sun.management.jmxremote.local.only=false\
-Dcom.sun.management.jmxremote.authenticate=false\
-Dcom.sun.management.jmxremote.ssl=false\
-Djava.rmi.server.hostname=185.83.15.228\
-Dcom.sun.management.jmxremote.port=9999\
-Dcom.sun.management.jmxremote.rmi.port=9999"
I think the problematic part might be the java.rmi.server.hostname property. I've set this to the IP of the host machine, but I've also tried other obvious things. I believe this should be the IP of the machine on which jconsole or jvisualvm will be running, but this is not working for me.
I start the container like this:
docker run -d -v /Users/timbo/tomcat-jmx.sh:/usr/local/tomcat/bin/setenv.sh -p 8080:8080 -p 9999:9999 tomcat:8.0
so port 9999 is exposed.
When I try to connect using jvisualvm connecting to localhost:9999 (which Docker for Mac will route to the container which is actually on 172.17.0.2) I get the error:
Cannot connect to localhost:9999 using service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi
Any hints on what is wrong?
OK, I think I managed to find it eventually. Setting the value of java.rmi.server.hostname to the hostname of the host (e.g. mymac.local, or whatever is returned by hostname) seem to get it working. All other settings were OK.
Docker for Mac works in a bit different way. The port you map actually gets mapped to the Linux VM it is running in the background. This VM usually has in IP 192.168.99.100. So you should try and connect to 192.168.99.100:9999
To verify what is the IP of your VM, open the Docker CLI terminal and execute below
echo $DOCKER_HOST
tcp://192.168.99.100:2376

Port forwarding issues trying to run a docker container

I am new to docker and nowhere near a networking expert, but I am seeing some strangeness when trying to run a docker container instance (right word?). I am running docker on OSX and set it up using the documentation found here: http://viget.com/extend/how-to-use-docker-on-os-x-the-missing-guide
Everything seems to have gone along fine, then I set up the port forwarding rules via these lines:
for i in {49000..49900};
do VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port$i,tcp,,$i,,$i";
done
I can confirm the boot2docker VM instance by checking the configuration within the Oracle VM VirtualBox Manager->Network->Adapter 1->Port Forwarding with the OSX.
I then run this command to get the container.
docker run -d -P dockerhub.emory.edu/ecoi_trunk:2
I do a "docker ps" and get this info.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f20bfefa2e97 dockerhub.emory.edu/ecoi_trunk:2 "/usr/sbin/apachectl 18 seconds ago Up 15 seconds 0.0.0.0:49153->443/tcp, 0.0.0.0:49154->80/tcp cranky_einstein
However, when I run an "lsof -i :49153" I see nothing is listening. I also can't reach the container via the "l****host:49153" in my browser. It just hangs.
What's strange is if I explicitly set the port (rather than allowing docker to assign one) via the following command:
docker run -d -p 49000:80 dockerhub.emory.edu/ecoi_trunk:2
It seems to work (lsof -i:49000 displays a TCP LISTEN), and I can confirm it's listening and the container is reachable via "l****host:49000". However, it's extremely slow. I'm not sure if either are related, but would welcome any tips or thoughts.

Resources