How to access Docker Selenium hub console in browser? - docker

I am running docker selenium hub on windows. The container is up as docker log shows. However I am confused at what is the actual hostname that the hub uses. When i use conventional Selenium hub, I can use http://localhost:4444/grid/console to check that it's running correctly. But in this case of docker, I am confused at the printing of Docker log.
I tried 0.0.0.0, localhost, 172.17.0.2 as hostname to open /grid/console in browser. None of them works.
Also when I tried to use 'netstat -a' to list all tcp connections, I do not see any of them has port 4444.
Could anyone let me know what went wrong?

You are running docker on windows, there are two things you can do.
Map your port 4444 to host when starting the container.
On windows, your container is ruining in Boot2Docker virtual machine.
So instead of http://localhost:4444/grid/console use
http://{ip of boot2docker vm}:4444/grid/console
To get IP on boot2docker machine try the following command:
docker-machine ip default
Port expose docker example:
docker run -d -p 4444:4444 --name <container-name> <image-name> 

Related

How do I configure docker to allow a connection to a container from other computers?

I am trying to run a small test server with MS SQL Server running on a Mac in a Linux docker container. Maybe I have the terminology wrong so please correct me if necessary:
host - the macOS desktop with docker installed (ip 10.0.1.73)
container - the Linux instance running in the docker container with SQL Server running in it
remote desktop - another computer on the local area network trying to connect to SQL Server
I followed the MS installation instructions and everything seems to be running fine, except I can't connect to SQL Server from the Remote Desktop
I can connect to the docker host(10.0.1.73) and can ping the IP address
I can connect to SQL Server from the docker host and see the databases etc.
I used the following command to create the docker container
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<XXXXXX>" -p 1433:1433 --name sqlserver1 -d microsoft/mssql-server-linux:2017-latest
Thinking that the -p 1433:1433 would map the linux port to the macOS host port and allow the remote computer to access the docker container when connecting to that port on the macOS host from the local area network
This is not working and I assume this may be to do with the network routing on the macOS host
Most solutions I have seen seem to indicate that one should use the VirtualBox UI to modify the network settings - but I don't have that installed
The others seem to have pages and pages of command line instructions that are required
Is there an easy solution somewhere I have missed?
EDIT:
Some more research and I found this explanation about how by default the Docker networking is set up for single host networking. Good explanation for anyone else struggling with the Docker concepts.
It is also worth reading up about the differences between docker containers and virtual machines...
https://youtu.be/Js_140tDlVI
Still trying to find some explanation on multi host networking.
try disabeling the firewall on the host you want to connect to.
port 1433 will be forwarded to the docker container, but your host (MAC) should have port 1433 open to be able to connect to your host.
Using NAT:
Assign the target address to your host interface:
sudo ifconfig en1 alias 10.0.1.74/21 up
Create the docker container and map the port to the second IP address assigned to the host interface
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<XXXXXXXXX>" -p 10.0.1.74:1433:1433 --name sqlserver1 -d microsoft/mssql-server-linux:2017-latest

How to access docker container via its Ip from the host

I want to be able to access a docker container via its Ip eg the one I can see when I do docker container inspect foo
The reason is I am using zookeeper inside a docker container that is managing two other docker containers running solr. My code (not in docker and I don't at this stage want it to be) calls zookeeper to get the urls of the solr servers which zookeeper reports as the docker containers ip. My code then falls over because calling the docker containers ip from the host fails as it should be calling localhost.
So how can I allow a call to the docker containers ip from the host to be routed correctly. (I am using Docker native for Mac)
I'm not using Docker for Mac, so I'm not sure the newest version Docker for Mac is still based on Docker-machine (which based on VirtualBox) or not.
If you can confirm your Docker for Mac is based on VirtualBox, then you probably could get the inet IP of vboxnet0 network interface via ifconfig command. This IP should be used as your calling IP.
Besides, you should know the port number of your Zookeeper container. Normally the exposed port of a container could be configured in docker run command, for example:
docker run -p 5000:5001 -i -t ubuntu /bin/bash
Where -p indicated the exposed port of the container.

docker running splash container but localhost does not load (windows 10)

I am following this tutorial to use splash to help with scraping webpages.I installed Docker toolbox and did these two steps:
$ docker pull scrapinghub/splash
$ docker run -p 5023:5023 -p 8050:8050 -p 8051:8051 scrapinghub/splash
I think it is running correctly, based on the prompted message in Docker window, which looks like this:
However, when I open the `localhost:8050' in a web browser, it says the localhost is not working.
What might have gone wrong in this case? Thanks!
You have mapped the port to your docker host (the VM), but you have not port-forwarded that same port to your actual "localhost" (your Windows host)
You need to declare that port-forwarding in the Network settings of your VM (for instance "default"), or with VBoxManage controlvm commands.
Then and only then could you access that port (used by your VM) from your Windows host (localhost).
That or you can access that same port using the IP address of your boot2docker VM: see docker-machine ls.
#user3768495, when you use http://192.168.99.100:8050/ , you are actually using the docker-machine ip and this ip would be available on your machine only and not on the network. To map it to localhost, you do need to port-forward the same port to your localhost. I was having the same issue and I detailed the process in below link.
https://stackoverflow.com/a/35737787/4820675

Docker container doesn't expose ports when --net=host is mentioned in the docker run command

I have a CentOS docker container on a CentOS docker host. When I use this command to run the docker image docker run -d --net=host -p 8777:8777 ceilometer:1.x the docker container get host's IP but doesn't have ports assigned to it.
If I run the same command without "--net=host" docker run -d -p 8777:8777 ceilometer:1.x docker exposes the ports but with a different IP. The docker version is 1.10.1. I want the docker container to have the same IP as the host with ports exposed. I also have mentioned in the Dockerfile the instruction EXPOSE 8777 but with no use when "--net=host" is mentioned in the docker run command.
I was confused by this answer. Apparently my docker image should be reachable on port 8080. But it wasn't. Then I read
https://docs.docker.com/network/host/
To quote
The host networking driver only works on Linux hosts, and is not supported on Docker for Mac, Docker for Windows, or Docker EE for Windows Server.
That's rather annoying as I'm on a Mac. The docker command should report an error rather than let me think it was meant to work.
Discussion on why it does not report an error
https://github.com/docker/for-mac/issues/2716
Not sure I'm convinced.
The docker version is 1.10.1. I want the docker container to have same ip as the host with ports exposed.
When you use --net=host it tells the container to use the hosts networking stack. So you can't expose ports to the host, because it is the host (as far as the network stack is concerned).
docker inspect might not show the expose ports, but if you have an application listening on a port, it will be available as if it were running on the host.
On Linux, I have always used --net=host when myapp needed to connect to an another docker container hosting PostgreSQL.
myapp reads an environment variable DATABASE in this example
Like Shane mentions this does not work on MacOS or Windows...
docker run -d -p 127.0.0.1:5432:5432 postgres:latest
So my app can't connect to my other other docker container:
docker run -e DATABASE=127.0.0.1:5432 --net=host myapp
To work around this, you can use host.docker.internal instead of 127.0.0.1 to resolve your hosts IP address.
Therefore, this works
docker run -e DATABASE=host.docker.internal:5432 -d myapp
Hope this saves someone time!

Docker container not exposed on network

I am new to docker. I am running it on windows. I am trying to get a container named "ghost" (available from the Docker Hub) to work on a Windows 8.1 machine. While the container starts correctly and supposedly exposes url at http://localhost:2368, when I enter this address nothing happens. The same has happened when trying other containers from the Hub which expose urls.
I tried accessing the container's exposed URL from the IP Address I get from the "docker ip" but it failed too. I also tried running the container with the "--net="bridge"" option, to no avail. I think I'm missing something pretty basic, but I can't for the life of me figure out what. Can someone point me in the right direction?
When you install Docker on Windows that means you most likely installed boot2docker.
boot2docker starts a minimal Linux VM (based on VirtualBox) because Docker requires a Linux kernel to run. The Docker daemon is started on that VM and not on your localhost.
You can determine the VMs IP address by typing boot2docker ip on your command line. The standard boot2docker IP address is 192.168.59.103 if you did not configure something else or have multiple instances of that VM running.
So when you execute docker run --name ghost -p 2368:2368 -d ghost the port 2368 is opened at 192.168.59.103:2368. That is where you need to connect to.
For more information please read the official boot2docker documentation.
You haven't provided the complete 'docker run ...' command you executed, so I'm assuming you ran the one specified in the image's page on Docker Hub (reproduced below).
docker run --name some-ghost -p 8080:2368 -d ghost
The command is mapping Ghost's exposed port inside the container (2368) to port 8080 in your boot2docker VM. The first thing you need to do is run boot2docker ip to find out the IP address of your boot2docker VM. About the port number, you have two options:
Access Ghost via port 8080 (http://BOOT2DOCKER-IP:8080)
Change the port mapping to expose 2368 (-p 2368:2368)

Resources