I using Test-Kitchen and Vagrant to do integration test on my cookbooks. But when I use kitchen login and enter into my VM to proof manually the status of apache2 service (I'm on ubuntu 12.04) there is not problems, it service is running but when I try to access from my host in this way
http://localhost:8080
and it not respond.
And it is my .kitchen.yml
---
driver:
name: vagrant
provisioner:
name: chef_solo
platforms:
- name: ubuntu-12.04
driver_config:
box: "ubuntu-12.04"
suites:
- name: default
run_list:
- recipe[web::default]
attributes:
My doubt is about if is necessary to configure something else on kitchen.yml, maybe something relative to netwotk..
You need to configure the port forwarding, or (IMHO a better option) a separate network interface with known IP address which you can use to connect to directly from the host.
For example:
driver:
network:
- ["private_network", { ip: "192.168.33.101" }]
See the kitchen-vagrant and Vagrant docs for more information.
Also make sure that apache binds to that (or all) interfaces. The same with port forwarding, as it will point to the default NAT interface, not to the loopback.
Related
This question already has answers here:
From inside of a Docker container, how do I connect to the localhost of the machine?
(40 answers)
Closed 1 year ago.
Firt of all: I don't want to connect to a docker container, running mongo.
I am building a docker container that should access the mongo database I have installed in my running Ubuntu 18.04 machine.
Docker suggests this could be done fairly easy by just adding the flag -pto the run command, so I did this:
docker run -p 27017:27017 --name mycontainer myimage
Port 27017 is the default port for mongo (see here) and running netstat -pna | grep 27017 confirms by returning the following:
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:27017 127.0.0.1:55880 ESTABLISHED -
tcp 0 0 127.0.0.1:55882 127.0.0.1:27017 ESTABLISHED -
tcp 0 0 127.0.0.1:55880 127.0.0.1:27017 ESTABLISHED -
tcp 0 0 127.0.0.1:27017 127.0.0.1:55884 ESTABLISHED -
tcp 0 0 127.0.0.1:27017 127.0.0.1:55882 ESTABLISHED -
tcp 0 0 127.0.0.1:55884 127.0.0.1:27017 ESTABLISHED -
unix 2 [ ACC ] STREAM LISTENING 77163 - /tmp/mongodb-27017.sock
But running the docker command shown above, I get an error indicating that I can't connect to the port because it is already in use (which is actually the whole point of connecting to it):
docker: Error response from daemon: driver failed programming external connectivity on endpoint mycontainer (1c69e178b48ee51ab2765479e0ecf3eea8f43e6420e34b878882db8d8d5e07dd): Error starting userland proxy: listen tcp4 0.0.0.0:27017: bind: address already in use.
ERRO[0000] error waiting for container: context canceled
How should I proceed? What did I do wrong?
This dependents on how your application connects to a database.
Almost all languages needs the connection parameters.
Example with nodes & mysql:
const knex = require('knex')({
client: 'mysql',
connection: {
host: '10.10.10.10',
user: 'root',
password: 'changeme',
database: 'stackoverflow'
},
debug: true
});
Example with python & mongo
import pymongo
conn = pymongo.MongoClient('mongodb://root:pass#10.10.10.10:27017/')
Traditionally these connection parameters are stored in a properties or configuration file. One per environment: dev, staging, prod, etc
Configuration file
If your application use this method to get the connection parameters, you just need to follow these steps:
set the ip, port, user, password in the configuration file. Usually inside of your source code: application.properties, config.yml, parameters.ini, etc
perform a docker build ... of your app.
perform a docker run ... of your app. In this step, you don't need to pass any mongo parameter because there are already "inside" of your app. Check this and this to understand why localhost is not used in docker.
Disadvantage: This approach works in simple scenarios but if you have several environments like dev, testing, staging, pre-prod, prod, etc you will need to perform a build for each environment because the connection parameters are inside of your app.
Environment variables
This is my favorite and also is recommended in several platforms like heroku, openshift, couldfoundry, etc
In this approach you just need one build. This image could be deployed on any environment just playing with the correct parameters before the run.
Example with nodes & mysql using environment variables:
const knex = require('knex')({
client: 'mysql',
connection: {
host: process.env.database_host,
user: process.env.database_user,
password: process.env.database_password,
database: process.env.database_database
},
debug: true
});
Example with python & mongo using environment variables:
import pymongo
import os
database_host = os.environ['database_host']
database_user = os.environ['database_user']
database_password = os.environ['database_password']
urlConnect = "mongodb://{}:{}#{}:27017/".format(database_user, database_password,database_host )
conn = pymongo.MongoClient(urlConnect)
As you can see, the source code does not need to read a properties file to get the connection parameters because it hopes they are available as environment variables
Finally, the steps with this approach will be:
perform a docker build ... of your app.
perform a docker run ... of your app. In this case, you need to sent the variables from host to your container
docker run -it -p 8080:80 \
-e "database_host=10.10.10.10" \
-e "database_user=root" \
-e "database_password=pass" \
--name my_app my_container:1.0
Remote variables
If you have a distributed environment, scalable, etc you will want to manage your variables.
Basically you will have a web console to create, edit, delete and export your variables. Also these variables must be injected to your docker container in a easy way.
Example of how Heroku offer you a way to manage your variables
Check:
#4 Centralized and manageable configuration
I am working on an app that for testing is hosted on web pack dev server.
I am using the following settings in my web pack.config file
devServer: {
host: 'mysite.local.co.uk',
port: '14500'
}
I have the following set in my hosts file on Mac
0.0.0.0 mysite.local.co.uk
I can now access the site on my Mac using http://mysite.local.co.uk:14500
I am trying to use a similar config to access the site from a windows 7 parallels desktop I have created.
I have done the following:
Set parallels network to shared
Set the hosts file windows to
[My Mac IP] mysite.local.co.uk
When I attempt to access the site from parallels I get no response
I have pinged [My Mac IP] and get reply's as would be expected.
I have tried setting host to 0.0.0.0 and as suggested here Github Issue
I am at a loss for how to make this work any suggestions would be greatly accepted
On macOS Mojave, go to Settings -> Sharing to see your Mac's network name.
It should say something like "Computers on your local network can access your computer at: YourComputerName.local". You can also change this name to something easier to remember and type.
On my Mac, this allows me to access my dev server via Parallels, Windows 10 and Chrome over port 8080. Not sure if the port matters.
In our development environment we have our Angular app running on a Mac in development mode (grunt serve)
From a browser on the Mac we can access it with http://localhost:9000/
How can we access it from IE on a VirtualBox?
We are using yo angular generator Gruntfile.js
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729
},
UPDATE:
The VirtualBox is installed, with Windows and IE, on the same Mac where I "grunt serve" and develop the Angular app
I can access the angular app from IE within VBox using URL: http://10.0.2.2
But something is still not working
1) In the Network panel
request.Name: livereload.js?snipver=1
request.Path: http://10.0.2.2:35729/
request.Protocol: pending
request.Status (Description): pending
2) In the Network panel there are no XHR requests listed
Maybe the problem is that the app is using REST endpoints which are on another server which is accessed through VPN ?
SOLVED:
The problem was not with V-Box network setup but with the way I was detecting localhost in the angular app (for DEV purposes)
I had:
var IS_LOCALHOST = (location.hostname.indexOf('localhost') > -1)
I changed it to
var IS_LOCALHOST = (location.hostname.indexOf('localhost') > -1) || (location.hostname.indexOf('10.0.2.2') > -1);
I use it for things like
var BASE_URL = IS_LOCALHOST ? 'http://dev.api.base.url' : 'http://' + location.hostname;
Where is the Virtualbox hosted? I'm assuming it's running some version of Windows since you ask about IE.
If the Virtualbox is running on the same host (physical machine) as the Angular app, it sounds like you need to set the VM to "host-only" networking mode.
See this: https://superuser.com/questions/303906/virtualbox-make-host-and-guest-os-talk-between-each-other
Once you have networking between the host and guest machines, you should be able to launch IE in the Virtualbox and type the IP address of the Mac and the port (:9000) and connect.
Make sure Grunt Serve is set to serve outside of "localhost." See this: Access node.js/grunt server through localhost:port on virtual machine
Also, make sure there aren't any firewall rules to interfere with requests to port 9000 on your Mac.
You can go to virtualbox network adapter settings for the windows OS and bridge both the connections. This way you will be able to access the angular app inside IE by giving the IP address, port of mac.
http://IP_OF_MAC:Port
In my protractor config file, I had this line, seleniumAddress: 'http://localhost:4444/wd/hub'. On running Protractor I was getting an error "ECONNREFUSED connect ECONNREFUSED". After going through lot of other existing issues and solutions, I removed "seleniumAddress" property. That resolved the issue. Selenium standalone server gets started. "Selenium standalone server started at http://192.168.1.156:64477/wd/hub"
But when I turn on the VPN, then I get an error "Error: Timed out waiting for the WebDriver server at http://192.168.1.156:63199/wd/hub", which I have been not able to resolve.
I am on a HP laptop which has Windows 7 Professional and I am using Cisco VPN.
(Hi, so I can't comment yet (low rep)...)
Could you try running webdriver-manager start before running protractor? It will run in the address http://localhost:4444/wd/hub which is the seleniumAddress referred to in the protractor config. Does that change anything?
This might be related (VPN-workaround): protractor stand alone selenium fails: Error: Timed out waiting for the WebDriver server at
Check the settings of the firewall that stays between Selenium standalone server (which might run also on your local host) and your working station (usually your localhost).
In my case (running on local Linux station) I had a very restrictive iptables firewall rules such that the WebDriver process launched on localhost could not access the Selenium standalone server which also run on localhost at whatever TCP port.
Just try to turn it off and check if that is the case ; then accommodate your firewall settings such that the respective connection passes your firewall rules.
If you want your scripts communicate directly with the Firefox|Chrome Driver (bypassing the Selenium server entirely) then try adding the directConnect: true in your protractor.conf.js
Git and other tools, often use the git: protocol for accessing files
in remote repositories. Some firewall configurations are blocking
git:// URLs, which leads to errors when trying to clone repositories
or download dependencies. (For example corporate firewalls are
"notorious" for blocking git:.)
If you run into this issue, you can force the use of https: instead,
by running the following command: git config --global
url."https://".insteadOf git://
(see Common Issues on Angular tutorial)
I'm using Java but this isn't necessarily a Java question. Google's "java-compat" image is Debian (3.16.7-ckt20-1+deb8u3~bpo70+1 (2016-01-19)).
Here is my Dockerfile:
FROM gcr.io/google_appengine/java-compat
RUN apt-get -qqy update && apt-get qqy install curl xvfb x11vnc
RUN mkdir -p ~/.vnc
RUN x11vnc -storepasswd xxxxxxxx ~/.vnc/passwd
EXPOSE 5900
ADD . /app
And in the Admin Console I created a firewall rule to open up 5900. And lastly I am calling the vnc server itself in the "_ah/start" startup hook with this command:
x11vnc -forever -usepw -create
All seems to be setup correctly but I'm unable to connect with TightVNC. I use the public (ephemeral) IP address for the instance I find in the Admin Console followed by ::5900 (TightVNC requires two colons for some reason). I'm getting a message that the server refused the connection. And indeed when I try to telnet to port 5900 it's blocked.
Next I SSH into the container machine and when I test the port on the container with wget xxx.xxx.xxx.xxx:5900 I get a connection. So it seems to me the container is not accepting connections on port 5900. Am I getting this right? Is it possible to open up ports and route my VNC client into the docker container? Any help appreciated.
Why I can't use Compute Engine. Just to preempt some comments about using google's Compute Engine environment instead of Managed VMs. I make heavy use of the Datastore and Task Queues in my code. I don't think those can run (or run natively/efficiently) on Compute Engine. But I may pose that as a separate question.
Update: Per Paul in the comments... having learned some of the docker terminology: Can I publish a port on the container in Google's environment?
Out of curiosity - why are you trying to VNC into your instances? If it's just for management purposes, you can SSH into Managed VM instances.
That having been said - you can use the network/forwarded_ports config to route traffic from the VM to the application container:
network:
forwarded_ports:
- 5900
instance_tag: vnc
Put that in your app.yaml, and re-deploy your app. You'll also need to open the port in your firewall (if you intend on accessing this from the public internet):
gcloud compute firewall-rules create default-allow-vnc \
--allow tcp:5900 \
--target-tags vnc \
--description "Allow vnc traffic on port 5900"
Hope this helps!