This guide explains how to deploy the Advanced Web Scraper API using Docker and Docker Compose.
git clone https://github.com/your-username/adv-web-scraper-api.git
cd adv-web-scraper-api
The application uses environment variables for configuration. A template file .env.docker is provided:
# Copy the template
cp .env.docker .env
Edit the .env file to set your specific configuration values:
# Open with your preferred editor
nano .env
Important variables to configure:
NODE_ENV: Set to production for production deploymentsMONGODB_URI: MongoDB connection string (default is fine if using the provided Docker Compose setup)REDIS_HOST and REDIS_PORT: Redis connection details (default is fine if using the provided Docker Compose setup)TWOCAPTCHA_API_KEY and ANTICAPTCHA_API_KEY: API keys for CAPTCHA solving services (if used)PROXY_API_URL and PROXY_API_KEY: Proxy service details (if used)BROWSER_POOL_MIN and BROWSER_POOL_MAX: Browser pool size configurationThe project includes a deployment script that simplifies the Docker Compose operations:
# Make the script executable (if not already)
chmod +x deploy.sh
# Deploy with default settings
./deploy.sh
# Or deploy with specific options
./deploy.sh -b -d # Build and run in detached mode
The deploy.sh script provides several options:
Options:
-h, --help Show help message
-e, --env FILE Specify environment file (default: .env.docker)
-b, --build Force rebuild of Docker images
-d, --detach Run containers in detached mode
-p, --pull Pull latest images before starting
-s, --stop Stop running containers
-r, --restart Restart containers
-l, --logs [SERVICE] View logs (optionally for a specific service)
--prune Remove unused Docker resources
After deployment, verify that all services are running:
docker-compose ps
You should see three services running:
app: The Advanced Web Scraper API applicationmongodb: MongoDB databaseredis: Redis cache and queueThe API will be available at:
http://localhost:3000
You can test it with a simple curl command:
curl http://localhost:3000/api/v1/health
To view logs from the services:
# View logs from all services
./deploy.sh -l
# View logs from a specific service
./deploy.sh -l app
To stop all services:
./deploy.sh -s
To restart all services:
./deploy.sh -r
To update the deployment with the latest code:
# Pull the latest code
git pull
# Restart with a rebuild
./deploy.sh -r -b
If you prefer to use Docker Compose directly instead of the deployment script:
# Start services
docker-compose --env-file .env up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down
# Rebuild and start
docker-compose up --build -d
The Docker Compose configuration sets up persistent volumes for:
mongodb-dataredis-data./logs directory./screenshots directory./browser-data directoryThese volumes ensure that your data persists across container restarts.
For production deployments, consider the following:
BROWSER_POOL_MIN and BROWSER_POOL_MAX based on your server resourcesdocker-compose logs appIf you encounter issues not covered in this guide: