This is a pre-configured, ready-to-run PostgreSQL with IP2Location Geolocation database setup scripts. It simplifies the development team to install and set up the geolocation database in PostgreSQL. The setup script supports the commercial database packages and free LITE package. Please register for a download account before running this image.
Run this image as daemon with your username, password, and download code registered from IP2Location.
docker run --name ip2location -d -e POSTGRESQL_PASSWORD=YOUR_POSTGRESQL_PASSWORD -e USERNAME=YOUR_USERNAME -e PASSWORD=YOUR_PASSWORD -e CODE=DOWNLOAD_CODE ip2location/postgresql
POSTGRESQL_PASSWORD – Enter a password for user admin.
USERNAME – Email address of the registered download account.
PASSWORD – Password of the registered download account.
CODE – The CSV file download code. You may get the download code from your account panel.
The installation may take minutes to hour depending on your internet speed and hardware. You may check the installation status by viewing the container logs. Run the below command to check the container log:
docker logs YOUR_CONTAINER_ID
You should see the line of
=> Setup completedif you have successfully complete the installation.
Connect to it from an application
docker run --link ip2location:ip2location-db -t -i application_using_the_ip2location_data
Make the query
psql -h ip2location-db --username=postgres -d ip2location_database
Enter YOUR_POSTGRESQL_PASSWORD password when prompted.
inet_to_bigint function for easier lookup.
CREATE OR REPLACE FUNCTION inet_to_bigint(inet) RETURNS bigint AS $$ SELECT $1 - inet '0.0.0.0' $$ LANGUAGE SQL strict immutable;GRANT execute ON FUNCTION inet_to_bigint(inet) TO public;
Start lookup by following query:
SELECT * FROM ip2location_database WHERE inet_to_bigint('220.127.116.11') <= ip_to LIMIT 1;