- The Redis container (for caching or sessions),
- The Database container (e.g., MySQL/PostgreSQL/etc.)
To enable communication between your containers, especially when using cPanel (which might be using Docker or Podman under the hood), you need to make sure they are:
- On the same Docker network
- Using the container name as hostname when calling each other
✅ Steps to ensure API can reach Redis and Database:
1. Use a custom bridge network
This ensures containers can talk to each other by name.
docker network create app-network
2. Run your containers on that network
# Redis
docker run -d --name redis --network app-network redis
# Database (example: PostgreSQL)
docker run -d --name db --network app-network -e POSTGRES_PASSWORD=secret postgres
# API
docker run -d --name api --network app-network your-api-image
3. Update your API configuration
For Redis:
REDIS_HOST=redis
REDIS_PORT=6379
For Database:
DB_HOST=db
DB_PORT=5432 # or 3306 for MySQL
Make sure your API code uses environment variables (or hardcoded names) like redis and db as hostnames.
🛠 If you're using cPanel's GUI:
If you're not using SSH but managing containers through cPanel's Docker Manager or Application Manager, look for:
A way to assign the same network name to all containers.
Define environment variables for REDIS_HOST and DB_HOST.