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.
-
Create a dedicated network so that your application containers can communicate with the IP2Location container by name.
docker network create ip2location-network
1. Run this image as daemon with your download token and download code registered from [IP2Location](https://www.ip2location.com) and attaching it to the network created above.
```bash
docker run --name ip2location \
--network ip2location-network \
-d \
-e POSTGRESQL_PASSWORD=YOUR_POSTGRESQL_PASSWORD \
-e TOKEN=YOUR_TOKEN \
-e CODE=DOWNLOAD_CODE \
ip2location/postgresql
**ENV Variables**
TOKEN - Download token form IP2Location account.
CODE - Database code. Codes available as below:
<u>Free Database</u>
* DB1-LITE, DB3-LITE, DB5-LITE, DB9-LITE, DB11-LITE
Commercial Database
- DB1, DB2, DB3, DB4, DB5, DB6, DB7, DB8, DB9, DB10, DB11, DB12, DB13, DB14, DB15, DB16, DB17, DB18, DB19, DB20, DB21, DB22, DB23, DB24, DB25,DB26
IP_TYPE - (Optional) Download IPv4 or IPv6 database. Script will download IPv4 database by default.
- IPV4 - Download IPv4 database only.
- IPV6 - Download IPv6 database only.
POSTGRESQL_PASSWORD - (Optional) Password for PostgreSQL admin. A random password will be generated by default.
-
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.
Run your application container on the same network. The IP2Location container is reachable by its container name (ip2location) as the hostname:
docker run --network ip2location-network -t -i {YOUR_APPLICATION}psql -h ip2location --username=postgres -d ip2location_databaseConnection to ip2location host, enter YOUR_POSTGRESQL_PASSWORD password when prompted.
Start lookup by following query:
SELECT * FROM ip2location_database WHERE ip2int('8.8.8.8') BETWEEN ip_from AND ip_to LIMIT 1;Notes: For IPv6 lookup, please convert the IPv6 into BigInt programmatically. There is no build-in function available with PostgreSQL.