Docker - URL syntax [duplicate] - docker

What is the format for the PostgreSQL connection string (URL postgres://...) when the host is not the localhost?

If you use Libpq binding for respective language, according to its documentation URI is formed as follows:
postgresql://[user[:password]#][netloc][:port][/dbname][?param1=value1&...]
Here are examples from same document
postgresql://
postgresql://localhost
postgresql://localhost:5432
postgresql://localhost/mydb
postgresql://user#localhost
postgresql://user:secret#localhost
postgresql://other#localhost/otherdb?connect_timeout=10&application_name=myapp
postgresql://localhost/mydb?user=other&password=secret

The following worked for me
const conString = "postgres://YourUserName:YourPassword#YourHostname:5432/YourDatabaseName";

DATABASE_URL=postgres://{user}:{password}#{hostname}:{port}/{database-name}

Here is the documentation for JDBC, the general URL is "jdbc:postgresql://host:port/database"
Chapter 3 here documents the ADO.NET connection string,
the general connection string is Server=host;Port=5432;User Id=username;Password=secret;Database=databasename;
PHP documentation us here, the general connection string is
host=hostname port=5432 dbname=databasename user=username password=secret
If you're using something else, you'll have to tell us.

the connection url for postgres
syntax:
"Server=host ipaddress;Port=5432;Database=dbname;User Id=userid;Password=password;
example:
"Server=192.168.1.163;Port=5432;Database=postgres;User Id=postgres;Password=root;

server.address=10.20.20.10
server.port=8080
database.user=username
database.password=password
spring.datasource.url=jdbc:postgresql://${server.address}/${server.port}?user=${database.user}&password=${database.password}

The connection string can also be retrieved programmatically from working DB connectors.
For instance I sometimes extract connection strings from SQLAlchemy's engine, like this:
> db_engine.url
postgres://{user}:{password}#{host}:{port}/{db_name}?sslmode=require

Some people seem to misread the database name as a server name and the host as a postgresql server? A host hosts a postgresql server that has a database. Or am I missing something.
postgresql://my_host/&server=my_postgresql_server?user=my_user&port=my_port&password=my_password&database=my_database
Example:
my_host: can be "localhost" (but that is not in the question) or an ip address of a host.
postgresql://my_host/&server=postgres?user=postgres&port=5432&password=postgres&database=test_db
Worked for me in Python with sqlalchemy and a postgresql localhost running. Needs sqlalchemy, postgresql, and psycopg2 to get it to work.
PS: The question is about a postgres://... URL, but this would not work here. Instead, you need postgresql, and what is run in the end in Python is dialect+driver (see Database URLs) = postgresql+psycopg2, without having to write it like this.

The general format of database url
DATABASE_URL=postgresql://username:password#host:port/dtabase_name
If you are using postgresql sql with asyncpg the database url would be
DATABASE_URL=postgresql+asyncpg://username:password#host:port/dtabase_name
Remember to never push your database password so you should use your DATABASE_URL in .env file
The port is optional if you use the default one
Like this you can connect both local and remote database think of that once you want to check an issue that occur in the remote deployed versions
ex of localhost DATABASE_URL would be
DATABASE_URL=postgresql+asyncpg://postgres:dina#localhost/mysens
If you deployed your database on Heroku and you want to connect it with your local app, go to Heroku Postgres installed add-on go to settings and click on view credential in Database Credentials and use the uri to connect to your database
DATABASE_URL=postgresql+asyncpg://sqnalxxxxxxxxx:160xxxx2bdd2942b26c93c392xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx#ec2-35-173-91-114.compute-1.amazonaws.com:5432/del6o4cjoqfsov

Related

How to use bolt protocol to access my Neo4j Database?

I am new to Neo4j and am reading this example:
try ( HelloWorldExample greeter = new HelloWorldExample( "bolt://localhost:7687", "neo4j", "test" ) )
{
greeter.printGreeting( "hello, world" );
}
In my Eclipse, this code works fine. However, I already have a Neo4j database which I can access through
http://localhost:7474/browser/
My question is in my Java code above, how can I access my existing Neo4j database? If I change "bolt://localhost:7687" to "http://localhost:7474", I received this error:
Exception in thread "main" org.neo4j.driver.v1.exceptions.ClientException: Unsupported URI scheme: http
at org.neo4j.driver.internal.DriverFactory.createDriver(DriverFactory.java:125)
at org.neo4j.driver.internal.DriverFactory.newInstance(DriverFactory.java:82)
at org.neo4j.driver.v1.GraphDatabase.driver(GraphDatabase.java:136)
at org.neo4j.driver.v1.GraphDatabase.driver(GraphDatabase.java:119)
at org.neo4j.driver.v1.GraphDatabase.driver(GraphDatabase.java:94)
at neo4j.Neo4j.<init>(Neo4j.java:19)
at neo4j.Neo4j.main(Neo4j.java:50)
So how can I access my existing database (http://localhost:7474) through 'bolt'?
You can access a Neo4j database through 2 protocols :
HTTP/REST on default port 7474
BOLT on default port 7687
So on your example, you are trying to use a BOLT client on the HTTP, this can't work.
So the good url is the one into your java code : "bolt://localhost:7687"

Getting IP Address current server

I used symfony 1.4 to create my application.
I'd like to get the IP adress of the current server to put it within soap request
So, how can i get the IP address of the current server?
For most situations, using $_SERVER['SERVER_ADDR']; will work. If that doesn't work you can try $ip = gethostbyname(gethostname());
If you have access to the $request object and it is a sfWebRequest (typical request from a browser) you can use:
$request->getPathInfoArray()['SERVER_ADDR']
Premise of the following method: your domain name has only one IP resolution
Using PHP:
gethostbyname($_SERVER['SERVER_NAME'])
$_SERVER['SERVER_NAME']will generally return your domain name (server_name / ServerName is configured in Nginx / Apache server), and then use gethostbyname().
About $_SERVER['SERVER_ADDR'], it often return a LAN IP address (I only have one server, one domain name, no reverse proxy; cloud server).
About gethostname()
In the test, it returns the name of the server (host name, not the domain name you use), and then uses gethostbyname(), will return a LAN IP.
More can be used https://checkip.amazonaws.com/ Get the current IP.

Connect to a password protected FTP through PROXY in Ruby

I'm trying to upload to my server (on Heroku) a file stored in a password protected FTP.
The problem is that this FTP also dont contain my production IP address on his whitelist (and i cant add it..) so i should use a proxy to connect my rails app this FTP.
I tried this code :
proxy_uri = URI(ENV['QUOTAGUARDSTATIC_URL'] || 'http://login:password#myproxy.com:9293')
Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port,"login","password").start('ftp://login:password#ftp.website.com') do |http|
http.get('/path/to/myfile.gz').body
end
But my http.get returns me lookup ftp: no such host.
I also got this code for FTP download, but i dont know how to make it works with a proxy :
ftp = Net::FTP.new('ftp.myftp.com', 'login', 'password')
ftp.chdir('path/to')
ftp.getbinaryfile('myfile.gz', 'public/myfile.gz', 1024)
ftp.close
Thanks in advance.
I realise that you asked this question over 6 months ago, but I recently had a similar issue and found that this (unanswered) question is the top Google result, so I thought I would share my findings.
mudasobwa's comment below your original post has a link to the net/ftp documentation which explains how to use a SOCKS proxy...
Although you don't mention a specific requirement for a HTTP proxy in your original post, it seems obvious to me that is what you were trying to use. As I'm sure you're aware, this makes the SOCKS documentation totally irrelevant.
The following code has been tested on ruby-1.8.7-p357 using an HTTP proxy that does not require authentication:
file = File.open('myfile.gz', 'w')
http = Net::HTTP.start('myproxy.com', '9293')
resp, data = http.get('ftp://login:password#ftp.website.com')
file.write(data) if resp.code == "200"
file.close unless file.nil?
Source
This should give you a good starting point to figure the rest out for yourself.
To get you going, I would guess that you could use user:pass#myproxy.com for basic auth, or perhaps sending a Proxy-Authorization header in your GET request.

Get own IP address

How to get my own IP address with Rails?
When I do it like this I got: 127.0.0.1
#ip = request.remote_ip
Is there any way to get the Public IP?
Try:
require 'socket'
ip=Socket.ip_address_list.detect{|intf| intf.ipv4_private?}
ip.ip_address if ip
I believe request.env['SERVER_NAME'] works, if you want to reflect the server base address back
Call the page using your IP, not localhost. I.e, 192.168.2.9:3000 in case of the default development environment would yield:
request.env['REMOTE_ADDR']
#=> 192.168.2.9
or:
request.remote_ip
#=> 192.168.2.9
As your request is local to the server, it returns the "localhost" address, i.e. 127.0.0.1.
If you request it from a machine hosted on the internet, it will give you a static IP of the remote server.
If you want the static IP of own internet then visit http://ping.eu and you can see your public IP.
Try this:
request.env['REMOTE_ADDR']
This does not answer this question. I think someone else can find this answer helpful.
Problem:
I am developing a mobile app. So, When I debug/hot reload/live reload the app in real mobile device. Images url does not work with localhost:3000.
Images works with ip like this: http://192.168.0.102:3000/user/1/profile-223hfkj33.jpg
Problem is Every time I turn on laptop and connect to wifi router, laptop ip changes. So, every-time I need to change asset_host in environments/development.rb file.
Looking at previous answers I found a solution:
Solution:
in environments/development.rb I write this code:
server_address = "#{Socket.ip_address_list.detect(&:ipv4_private?).try(:ip_address)}:3000"
config.asset_host = server_address
puts "Server address: #{server_address}"
# when I run `rails s`, this line prints server address in console
So, It sets asset_host like this: 192.168.0.102:3000
And when I turn on laptop, laptop gets new ip address and it works.

How to check server connection

i want to check my server connection to know if its available or not to inform the user..
so how to send a pkg or msg to the server (it's not SQL server; it's a server contains some serviecs) ...
thnx in adcvance ..
With all the possibilities for firewalls blocking ICMP packets or specific ports, the only way to guarantee that a service is running is to do something that uses that service.
For instance, if it were a JDBC server, you could execute a non-destructive SQL query, such as select * from sysibm.sysdummy1 for DB2. If it's a HTTP server, you could create a GET packet for index.htm.
If you actually have control over the service, it's a simple matter to create a special sub-service to handle these requests (such as you send through a CHECK packet and get back an OKAY response).
That way, you avoid all the possible firewall issues and the test is a true end-to-end one. PINGs and traceroutes will be able to tell if you can get to the machine (firewalls permitting) but they won't tell you if your service is functioning.
Take this from someone who's had to battle the network gods in a corporate environment where machines are locked up as tight as the proverbial fishes ...
If you can open a port but don't want to use ping (i dont know why but hey) you could use something like this:
import socket
host = ''
port = 55555
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host, port))
s.listen(1)
while 1:
try:
clientsock, clientaddr = s.accept()
clientsock.sendall('alive')
clientsock.close()
except:
pass
which is nothing more then a simple python socket server listening on 55555 and returning alive

Resources