Connect to Selenium within Docker-container - selenium

I'm developing tests with Selenium. Currently I'm using official selenium/standalone-chrome:3.11.0 image. I'm running only Selenium inside Docker-container. The project itself is compiled on the host machine (tests connect to the container's exposed port):
$ docker run -p 4444:4444 selenium/standalone-chrome:3.11.0
$ curl -v localhost:4444
* Rebuilt URL to: localhost:4444/
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4444 (#0)
> GET / HTTP/1.1
> Host: localhost:4444
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 OK
...
But I would like to compile and test the project entirely inside Docker-container. So I created my own image upon selenium/standalone-chrome:3.11.0. My (simplified) Dockerfile looks like this:
FROM selenium/standalone-chrome:3.11.0
RUN sudo apt-get --assume-yes --quiet update
RUN sudo apt-get --assume-yes --quiet install curl
CMD ["curl", "-v", "localhost:4444"]
As can be seen from the file, I'm trying to connect to port 4444 within container. When I run the image, e.g.:
docker build -t test . && docker run test
I get:
* Rebuilt URL to: localhost:4444/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 127.0.0.1...
* connect to 127.0.0.1 port 4444 failed: Connection refused
* Trying ::1...
* Immediate connect fail for ::1: Cannot assign requested address
* Trying ::1...
* Immediate connect fail for ::1: Cannot assign requested address
* Failed to connect to localhost port 4444: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 4444: Connection refused
Why I'm not able to connect to Selenium which is ran inside container from the same container?

I've found the solution at last (sorry for my stupidity).
Building an image upon selenium/standalone-chrome:3.11.0 is not sufficient. You need to start Selenium explicitly.
The Dockerfile:
FROM selenium/standalone-chrome:3.11.0
WORKDIR /app
COPY . /app
RUN sudo apt-get --assume-yes --quiet update
RUN sudo apt-get --assume-yes --quiet install curl
CMD ["./acceptance.sh"]
The acceptance.sh wrapper script:
#!/bin/bash
set -x
set -e
/opt/bin/entry_point.sh &
# It will be better to look into log and wait for
# record 'Selenium Server is up and running on port 4444'.
# But in this script simplified approach is used, just for
# the sake of brevity.
sleep 30
curl -v localhost:4444
The result:
...
+ set -e
+ sleep 30
+ /opt/bin/entry_point.sh
07:51:35.092 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.11.0', revision: 'e59cfb3'
07:51:35.095 INFO [GridLauncherV3$1.launch] - Launching a standalone Selenium Server on port 4444
2018-05-15 07:51:35.661:INFO::main: Logging initialized #2436ms to org.seleniumhq.jetty9.util.log.StdErrLog
07:51:36.448 INFO [SeleniumServer.boot] - Welcome to Selenium for Workgroups....
07:51:36.450 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
^[[23;5~^[[23;5~+ curl -v localhost:4444
* Rebuilt URL to: localhost:4444/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4444 (#0)
> GET / HTTP/1.1
> Host: localhost:4444
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 OK
...
Cheers!

Related

vscode insiders connection error after update

Vscode insiders stopped to work with remote today morning after (unavoidble) update. It doesn't show remote directory, saying
Connection error: Unauthorized client refused.
and
Failed to connect to the remote extension host server (Error:
Connection error: Unauthorized client refused.)
Deletion of all remote vscode files and killing vscode processes didn't help.
The following transcript can be seen in Output tab:
remote-ssh#0.44.0
linux x64
SSH Resolver called for "ssh-remote+myserver", attempt 1
SSH Resolver called for host: myserver
Setting up SSH remote "myserver"
Using commit id "MYHASH" and quality "insider" for server
Testing ssh with ssh -V
ssh exited with code: 0
Got stderr from ssh: OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017
Install and start server if needed
> Found existing installation at /home/dimskraft/.vscode-server-insiders/bin/MYHASH...
> Found running server...
>
> *
> * Reminder: You may only use this software with Visual Studio family products,
> * as described in the license (https://go.microsoft.com/fwlink/?linkid=2077057)
> *
>
> Checking server status with wget
> ==MY-GUID==
"install" terminal command done
Received install output: ==MY-GUID==
Server is listening on port 35693
Spawning tunnel with: "ssh" -L 127.0.0.1:35693:127.0.0.1:35693 -o ConnectTimeout=15 "myserver" bash << 'EOSSH'
echo -e 'Connected to SSH Host - Please do not close this terminal' && sleep infinity
EOSSH
> Connected to SSH Host - Please do not close this terminal
Spawned SSH tunnel between local port 35693 and remote port 35693
Waiting for ssh tunnel to be ready
Tunneling remote port 35693 to local port 35693
Resolved "ssh-remote+myserver" to "127.0.0.1:35693"
------
Downgrading to 1.36.0-insider helped

Access my AWS EC2 server index.html from external browser

I've been setting up an AWS EC2 server this week, and I'm almost there with what I want to do. But opening up as a web server is proving to be a stumbling block.
MY SETUP
I have an AWS EC2 instance running Red Hat EL7.
I have an Apache server running on my instance:
[ec2-user#ip-172-xx-xx-xx ~]$ ps -ef | grep -i httpd
root 18162 1 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 18163 18162 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 18164 18162 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 18165 18162 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 18166 18162 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 18167 18162 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
ec2-user 21345 20507 0 19:03 pts/1 00:00:00 grep --color=auto -i httpd
It seems to be listening on port 80:
[root#ip-172-xx-xx-xx ~]# netstat -lntp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 18162/httpd
I added inbound rules to the "launch-wizard-1" security group (which is shown as the security group for the instance) for port 80 (HTTP) and 443 (HTTPS) with sources of "0.0.0.0/0" and "::/0"
And finally, for testing my setup, I created an index.html file in my document root (/var/www/html):
<html>
<h1>TEST!</h1>
</html>
THE PROBLEM
From my chrome browser on my computer, when I try to hit:
http://ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com/index.html
I just get:
This page isn’t working
ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com didn’t send any data.
ERR_EMPTY_RESPONSE
(I get the same when I hit one of my domain names which I've set up on there, which is what I'm really trying to do of course!)
I've tried connecting from Chrome on 2 different computers, and from Safari on my phone ("Safari cannot open the page because it could not connect to the server")
CHECKS I'VE PERFORMED
I don't believe I have any server firewall preventing this:
[root#ip-xx-xx-xx-xx conf]# /sbin/iptables -L -v -n
Chain INPUT (policy ACCEPT 3575 packets, 275K bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 2215 packets, 350K bytes)
pkts bytes target prot opt in out source destination
Testing with telnet from a terminal session on my mac, port 80 appears to be open. Firstly using the IPv2 Public IP:
telnet 18.xxx.xxx.xx 80
Trying 18.xxx.xxx.xx...
Connected to ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com.
Escape character is '^]'.
Connection closed by foreign host.
and using the Public DNS (IPv4):
telnet ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com 80
Trying 18.xxx.xxx.xx...
Connected to ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com.
Escape character is '^]'.
Connection closed by foreign host.
And again, the same goes for my domain names - telnet to port 80 shows "Connected".
- Is the fact that the "foreign host" closes the connection immediately significant? Should it stay open if everything is working as it should?
Running curl on the host correctly returns my simple index.html file:
[ec2-user#ip-172-xx-xx-xx ~]$ curl localhost
<html>
<h1>TEST!</h1>
</html>
However, running a curl on my local computer - to the server - returns:
curl -v http://ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com:80
* Rebuilt URL to: http://ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com:80/
* Trying 18.xxx.xxx.xx...
* Connected to ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com (18.xxx.xxx.xx) port 80 (#0)
> GET / HTTP/1.1
> Host: ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com
> User-Agent: curl/7.43.0
> Accept: */*
>
* Empty reply from server
* Connection #0 to host ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com left intact
curl: (52) Empty reply from server
I also tested the webserver "internally" by running google chrome (headless) on the server to create a screenshot, downloaded to my local computer and it shows TEST! (i.e. its working):
google-chrome-stable --headless --disable-gpu --screenshot http://localhost
One more thing to add - when I attempt the hit the webserver from my local machine, nothing shows in the webserver logs (error_log or access_log) on the server.
So, my opinion is that the web server is up and running, works locally, but is not working correctly for anything coming from "outside". I'm stumped now though.
Doh! I rebooted the instance and.. all working now!
22 years working with computers and it took me 22 hrs to resort to a reboot. Fool!
Connect to your EC2 instance using ssh on terminal
Install python if not installed
Start a python server using nohup to continuously use the server
nohup python -m http.server &
This usually open port 8000, goto EC2 Security Group Make source anywhere or as needed.
Navigate to the folder having index.html, file path will look like below
http://ec2---.compute-1.amazonaws.com:8000/folder/website/
You will be able to develop and see your changes as needed.

Nagios CHECK_NRPE Could not complete SSL handshake

I checked all over, there are many answers to this issue, but none worked.
I am following this tutorial:
https://www.digitalocean.com/community/tutorials/how-to-install-nagios-4-and-monitor-your-servers-on-ubuntu-16-04
The Nagios host is ubuntu 16.04, the client is ubuntu 18.04
Nagios® Core™ 4.3.4
The Nagios server and web is running ok, I can see the localhost status us 'up' in the dashboard.
Something very weird: I installed NRPE 3.2.1 on both the host and the client, but for some reason on the host is 2.15
Host:
root#nagios-1:/tmp/nrpe-nrpe-3.2.1# /usr/local/nagios/libexec/check_nrpe -H 10.142.0.50
NRPE v2.15
Client:
$ /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v3.2.1
Just to make sure, when running check_nrpe from client to server I am using '-2' option to force v2 packets, but I am still getting to error
I added the client ip to the nrpe.cnf (on server), and to be sure also the server ip to the client nrpe.cfg file.
I enabled debug to see the messages in the syslog. this is the response:
Dec 4 00:35:47 nagios-1 check_nrpe: Remote 10.142.0.50 accepted a Version 2 Packet
Dec 4 00:35:51 nagios-1 nrpe[9953]: Connection from 10.142.0.11 port 49889
Dec 4 00:35:51 nagios-1 nrpe[9953]: Host address is in allowed_hosts
Dec 4 00:35:51 nagios-1 nrpe[9953]: Handling the connection...
Dec 4 00:35:51 nagios-1 nrpe[9953]: Error: Could not complete SSL handshake. 1
Dec 4 00:35:51 nagios-1 nrpe[9953]: Connection from closed.
On the host, port 5666 is open and listening
# netstat -at | grep nrpe
tcp 0 0 *:nrpe *:* LISTEN
tcp6 0 0 [::]:nrpe [::]:* LISTEN
I compiled nrpe with --
I am not using xinetd. I use the daemon
# ps aux | grep nrpe
nagios 9866 0.0 0.1 23960 2680 ? Ss 00:35 0:00 /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -d
Host nrpe conf file:
# grep -o '^[^#]*' /etc/nagios/nrpe.cfg
log_facility=daemon
pid_file=/var/run/nagios/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=127.0.0.1, 10.142.0.50, 10.142.0.0/20,10.142.0.11
dont_blame_nrpe=1
allow_bash_command_substitution=0
debug=1
command_timeout=60
connection_timeout=300
command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
include=/etc/nagios/nrpe_local.cfg
include_dir=/etc/nagios/nrpe.d/
If you need more info let me know and I will add it.
I found the answer!
I had two versions of NRPE on the host. The deamon was running 2.15. I had to kill this version, and I manually run the 3.2.1 version from its other location
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -f
After that I was able to get a response in the client

How can I supervised-ise .NET Core Web App?

This works:
$ dotnet bin/Debug/netcoreapp1.0/aspnetcoreapp.dll &
[1] 42350
Hosting environment: Production
Content root path: /home/foo/aspnetcoreapp
Now listening on: http://localhost:8080
Application started. Press Ctrl+C to shut down.
$ curl http://localhost:8080
(returns html)
While referring https://learn.microsoft.com/en-us/aspnet/core/publishing/linuxproduction , I wrote /etc/supervisord.conf as follows:
[program:aspnetcoreapp]
directory=/home/foo/aspnetcoreapp
command=/usr/local/bin/dotnet /home/foo/aspnetcoreapp/bin/Debug/netcoreapp1.0/aspnetcoreapp.dll
enviromnent=ASPNETCORE_ENVIRONMENT=Production
user=foo
stdout_logfile=/var/tmp/aspnetcoreapp.log
stderr_logfile=/var/tmp/aspnetcoreapp.log
autostart=true
Then I start supervisord.
$ supervisorctl start
The app seems running.
$ cat /var/tmp/aspnetcoreapp.log
Hosting environment: Production
Content root path: /home/foo/aspnetcoreapp
Now listening on: http://localhost:8080
Application started. Press Ctrl+C to shut down.
But the app returns 500 error.
$ curl -v http://localhost:8080
* About to connect() to localhost port 8080 (#0)
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 500 Internal Server Error
< Date: Mon, 26 Dec 2016 19:38:41 GMT
< Content-Length: 0
< Server: Kestrel
<
* Connection #0 to host localhost left intact
informations:
$ dotnet --info
.NET Command Line Tools (1.0.0-preview4-004233)
Product Information:
Version: 1.0.0-preview4-004233
Commit SHA-1 hash: 8cec61c6f7
Runtime Environment:
OS Name: centos
OS Version: 7
OS Platform: Linux
RID: centos.7-x64
Base Path: /opt/dotnet1.0.0-preview4-004233/sdk/1.0.0-preview4-004233

docker: Says connection refused when attempting to connect to a published port

I'm a newbie at docker. I'm creating a Hello, World example. All I'm trying to do is bring up Apache in a docker and then view the default website from the host machine.
Dockerfile
FROM centos:latest
RUN yum install epel-release -y
RUN yum install wget -y
RUN yum install httpd -y
EXPOSE 80
ENTRYPOINT ["/usr/sbin/httpd", "-D", "FOREGROUND"]
And then I build it:
> docker build .
And then I tag it:
docker tag 17283f566320 my:apache
And then I run it:
> docker run -p 80:9191 my:apache
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
It then runs....
In another terminal window, I attempt to issue the curl command to view the default web site.
> curl -XGET http://0.0.0.0:9191
curl: (7) Failed to connect to 0.0.0.0 port 9191: Connection refused
> curl -XGET http://localhost:9191
curl: (7) Failed to connect to localhost port 9191: Connection refused
> curl -XGET http://127.0.0.1:9191
curl: (7) Failed to connect to 127.0.0.1 port 9191: Connection refused
or I try localhost
Just to make sure that I got the port correct, I run this:
> docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5aed4063b1f6 my:apachep "/usr/sbin/httpd -D F" 43 seconds ago Up 42 seconds 80/tcp, 0.0.0.0:80->9191/tcp angry_hodgkin
Thanks to all. My ports were reversed:
> docker run -p 9191:80 my:apache
Despite you created the containers in your local machine. These are actually running on a different machine (a virtual machine)
First, check what is the IP of your docker machine (the virtual machine)
$docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
default * virtualbox Running tcp://192.168.99.100
Then run curl command to view the default web site on your apache web server inside the container
curl http://192.168.99.100:9191
If you are running docker on Ubuntu machine as native you should be able to access your container with localhost.
If you are using Mac or Windows your docker container runs not on local host but on its IP. you can get your container ip with command docker inspect <container id> | grep IPAddress or if your are using docker-machine docker-machine ip <docker_machine_name>
Related info:
http://networkstatic.net/10-examples-of-how-to-get-docker-container-ip-address/
https://docs.docker.com/machine/reference/ip/
How to get a Docker container's IP address from the host?
so your curl call should be something like this curl <container_ip>:<container_exposed_port>
also you can tag your image on build command with param -t like this:
docker build -t my:image .
Another tip you can optimize your dockerfile by combining yum install commands like this:
RUN yum install -y \
epel-release \
wget \
httpd
http://blog.tutum.co/2014/10/22/how-to-optimize-your-dockerfile/