https://github.com/ip2location/docker-ip2proxy-mongodb
This is a pre-configured, ready-to-run MongoDB server with IP2Proxy database setup scripts. It simplifies the development team to install and set up the geolocation database in MongoDB server.
https://github.com/ip2location/docker-ip2proxy-mongodb
Last synced: 5 months ago
JSON representation
This is a pre-configured, ready-to-run MongoDB server with IP2Proxy database setup scripts. It simplifies the development team to install and set up the geolocation database in MongoDB server.
- Host: GitHub
- URL: https://github.com/ip2location/docker-ip2proxy-mongodb
- Owner: ip2location
- Created: 2021-08-04T05:53:44.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-02-05T02:23:06.000Z (over 1 year ago)
- Last Synced: 2025-04-18T21:16:48.359Z (over 1 year ago)
- Language: Shell
- Size: 5.86 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
docker-ip2proxy-mongodb
==========================
This is a pre-configured, ready-to-run MongoDB server with IP2Proxy Proxy IP database. It simplifies the development team to install and set up the proxy IP database in MongoDB server. The setup script supports the [commercial database packages](https://www.ip2location.com/database/ip2proxy) and [free LITE package](https://lite.ip2location.com). Please register for a download account before running this image.
### Usage
1. Run this image as daemon using the download token and product code from [IP2Location LITE](https://lite.ip2location.com) or [IP2Location](https://www.ip2location.com).
```bash
docker run --name ip2proxy -d -e TOKEN={DOWNLOAD_TOKEN} -e CODE={DOWNLOAD_CODE} -e MONGODB_PASSWORD={MONGODB_PASSWORD} ip2proxy/mongodb
```
**ENV VARIABLE**
TOKEN – Download token obtained from IP2Location.
CODE – The CSV file download code. You may get the download code from your account panel.
MONGODB_PASSWORD - Password for MongoDB admin.
2. The installation may take seconds to minutes depending on your database sizes, downloading speed and hardware specs. You may check the installation status by viewing the container logs. Run the below command to check the container log:
```bash
docker logs -f ip2proxy
```
You should see the line `=> Setup completed` if you have successfully completed the installation.
### To create a test container
1. Download Debian Docker image.
```bash
sudo docker pull debian
```
2. Start the container in interactive mode.
```bash
sudo docker run --name debian-test -it debian bin/bash
```
3. Press Ctrl+P then Ctrl+Q to detach from the container. Please do not type the **exit** command as it will shut down the container, as we still need the container to be up and running for the testing.
### To create a network bridge to allow both containers to communicate
1. Create the network bridge.
```bash
sudo docker network create simple-network
```
2. Connect both containers to the same network using the below command.
```bash
sudo docker network connect simple-network ip2proxy
sudo docker network connect simple-network debian-test
```
### Query for IP information
1. Go back to the debian-test container.
```bash
sudo docker attach debian-test
```
2. Install MongoDB and Mongo Shell first by following the installation steps in https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/.
3. Run the Mongo Shell with the password you've specified during the installation.
```bash
mongosh --host ip2proxy -u mongoAdmin -p {MONGODB_PASSWORD} --authenticationDatabase admin
```
4. To test the IPv4 database, key in the commands below to query proxy info for IPv4 address 8.8.8.8 (IP number: 134744072).
```
use ip2proxy_database
db.ip2proxy_database.findOne( { $and: [ { ip_from: { $lte: 134744072 } }, { ip_to: { $gte: 134744072 } } ] } )
```
5. To test the IPv6 database, key in the commands below to query proxy info for IPv6 address 2001:4860:4860::8888 (IP number: 42541956123769884636017138956568135816).
```
use ip2proxy_database
db.ip2proxy_database.findOne( { $and: [ { ip_from_index: { $lte: "A0042541956123769884636017138956568135816" } }, { ip_to_index: { $gte: "A0042541956123769884636017138956568135816" } } ] } )
```
If you don't know how to convert an IP address to IP number, please see [IP2Location FAQs](https://www.ip2location.com/faqs#technical).
**NOTES**: The search param for IPv4 database is a number BUT the param for IPv6 database is a string of the IP number left-padded with zeroes till 40 characters and prefixed with an "A".
Also, IPv6 database is filtering on the ip_from_index and ip_to_index fields while IPv4 database is filtering on the ip_from and ip_to fields.
When querying IPv4 address using the IPv6 database, you need to convert the IPv4 address into [IPv4-mapped IPv6 address](https://blog.ip2location.com/knowledge-base/ipv4-mapped-ipv6-address/) before converting to IP number.
### Update IP2Proxy Database
To update your IP2Proxy database to latest version, please run the following command:
```bash
docker exec -it ip2proxy ./update.sh
```
### Articles and Tutorials
You can visit the below link for more information about this docker image:
[IP2Proxy Articles and Tutorials](https://blog.ip2location.com)