π Quick Start: docker run -d --network host -e DEFAULT_MAC="AA:BB:CC:DD:EE:FF" ghcr.io/cleeryy/wakeonlan-api
A simple and lightweight REST API built with FastAPI to remotely wake devices using Wake-on-LAN (WoL) magic packets. Send HTTP requests to wake up computers and devices on your network.
- RESTful API with FastAPI framework
- Wake devices by MAC address via HTTP requests
- Default MAC configuration for quick access
- Pre-built Docker images available on GitHub Container Registry
- Docker support with multi-stage builds
- Security-focused with non-root container user
- Lightweight Python 3.12-slim base image
- Environment-based configuration
No need to clone the repository! Just run the pre-built image:
# Pull and run the latest image with host networking
docker run -d \
--network host \
-e DEFAULT_MAC="AA:BB:CC:DD:EE:FF" \
--name wakeonlan-api \
ghcr.io/cleeryy/wakeonlan-api:latest
The API will be available at http://localhost:8080
Replace AA:BB:CC:DD:EE:FF with your device's actual MAC address.
- Create a docker-compose.yml file
services:
wakeonlan-api:
image: ghcr.io/cleeryy/wakeonlan-api:latest
network_mode: host
environment:
- DEFAULT_MAC=${DEFAULT_MAC}
env_file:
- .env
restart: unless-stopped
- Create a .env file
DEFAULT_MAC=AA:BB:CC:DD:EE:FF
- Start the service
docker compose up -d
- Clone the repository
git clone https://github.com/cleeryy/wakeonlan-api
cd wakeonlan-api
- Configure environment
cp .env.example .env
# Edit .env with your default MAC address
- Update docker-compose.yml for host networking
services:
wakeonlan-api:
build: .
network_mode: host
environment:
- DEFAULT_MAC=${DEFAULT_MAC}
env_file:
- .env
restart: unless-stopped
- Start the service
docker compose up --build -d
Wake-on-LAN requires host networking mode for the following reasons:
- Broadcast Packets: WoL magic packets are broadcast packets that need to reach devices on your physical network
- Docker Isolation: Docker's default bridge networking creates an isolated network that prevents broadcasts from reaching their intended targets
- Network Access: Host networking gives the container direct access to the host's network interface, allowing magic packets to properly broadcast to all network devices
Without host networking, the Wake-on-LAN packets will be trapped within Docker's internal network and won't reach the devices you want to wake up.
| Variable | Description | Default | Required |
|---|---|---|---|
DEFAULT_MAC |
Default MAC address for /wake endpoint |
None | Yes |
Set environment variables directly in the docker run command:
docker run -d \
--network host \
-e DEFAULT_MAC="AA:BB:CC:DD:EE:FF" \
--name wakeonlan-api \
ghcr.io/cleeryy/wakeonlan-api:latest
Create a .env file in your project directory:
# Default MAC address for /wake endpoint
DEFAULT_MAC=AA:BB:CC:DD:EE:FF
Welcome endpoint - Check if the API is running
Response:
{
"status": 200,
"message": "Welcome to the Wake-on-LAN API!"
}
Wake default device - Send WoL packet to the configured default MAC address
Response (Success):
{
"message": "Wake-on-LAN packet sent successfully"
}
Response (Error):
{
"error": "Failed to send Wake-on-LAN packet: [error details]"
}
Wake specific device - Send WoL packet to a specific MAC address
Parameters:
mac_address(path): Target device MAC address (format:AA:BB:CC:DD:EE:FF)
Response (Success):
{
"message": "Wake-on-LAN packet sent successfully to AA:BB:CC:DD:EE:FF device!"
}
# Check API status
curl http://localhost:8080/
# Wake default device
curl http://localhost:8080/wake
# Wake specific device
curl http://localhost:8080/wake/AA:BB:CC:DD:EE:FF
# Wake default device
http GET localhost:8080/wake
# Wake specific device
http GET localhost:8080/wake/AA:BB:CC:DD:EE:FF
import requests
# Wake default device
response = requests.get("http://localhost:8080/wake")
print(response.json())
# Wake specific device
mac_address = "AA:BB:CC:DD:EE:FF"
response = requests.get(f"http://localhost:8080/wake/{mac_address}")
print(response.json())
# Pull the latest image
docker pull ghcr.io/cleeryy/wakeonlan-api:latest
# Or pull a specific version
docker pull ghcr.io/cleeryy/wakeonlan-api:v1.0.0
docker run -d \
--network host \
-e DEFAULT_MAC="AA:BB:CC:DD:EE:FF" \
--name wakeonlan-api \
ghcr.io/cleeryy/wakeonlan-api:latest
# Clone repository first
git clone https://github.com/cleeryy/wakeonlan-api
cd wakeonlan-api
# Build image
docker build -t wakeonlan-api .
# Run built image with host networking
docker run -d \
--network host \
-e DEFAULT_MAC="AA:BB:CC:DD:EE:FF" \
--name wakeonlan-api \
wakeonlan-api
# View logs
docker logs wakeonlan-api
# Stop container
docker stop wakeonlan-api
# Remove container
docker rm wakeonlan-api
# Using Docker Compose
docker compose logs -f # View logs
docker compose down # Stop services
docker compose pull # Update to latest image
- Network Access: Ensure the API is only accessible from trusted networks
- Host Networking: Container shares host's network namespace for WoL functionality
- Container Security: The application runs as a non-root user inside the container
- MAC Address Validation: Consider implementing MAC address format validation for production use
- Firewall Rules: Configure appropriate firewall rules if needed
- Clone the repository
git clone https://github.com/cleeryy/wakeonlan-api
cd wakeonlan-api
- Install Python dependencies
pip install -r requirements.txt
- Set environment variables
export DEFAULT_MAC="AA:BB:CC:DD:EE:FF"
- Run the application
cd app
uvicorn main:app --host 0.0.0.0 --port 8080
wakeonlan-api/
βββ app/
β βββ __init__.py
β βββ main.py # FastAPI application
βββ docker-compose.yml # Docker Compose configuration
βββ Dockerfile # Docker image definition
βββ requirements.txt # Python dependencies
βββ .env.example # Environment template
βββ LICENSE # MIT License
- Python 3.12+
- FastAPI - Web framework
- wakeonlan - Python Wake-on-LAN library
- uvicorn - ASGI server
- python-dotenv - Environment variables support
Q: Wake-on-LAN packet sent but device doesn't wake up?
- Ensure Wake-on-LAN is enabled in device BIOS/UEFI
- Check network adapter WoL settings
- Verify the device is connected via Ethernet (not WiFi)
- Ensure the MAC address format is correct (
AA:BB:CC:DD:EE:FF) - Verify host networking is enabled - this is the most common issue!
Q: API returns connection errors?
- Verify the API is running:
docker logs wakeonlan-api - Check if the container is using host networking:
docker inspect wakeonlan-api | grep NetworkMode - Ensure Docker is running properly
Q: Container can't access the network?
- Make sure you're using
--network hostornetwork_mode: host - Check that the host system can send WoL packets
- Verify firewall settings on the host
Made with β€οΈ by ClΓ©ry Arque-Ferradou