Reputation: 349
I have a docker container running a python uwsgi app. The app sends a wake on lan broadcast packet to wake a pc in the local network.
It works fine without the use of docker (normal uwsgi app directly on the server), but with docker it won't work.
I exposed port 9/udp and bound it port 9 of the host system.
What am I missing here? Or with other words, how can I send a wake on lan command from a docker container to the outside network?
Upvotes: 13
Views: 10597
Reputation: 2224
There are a couple of other options you can consider to send the WoL packet outside of the docker private network if you don't want to expose the container to the host network using the already mentioned --network host
approach.
The first option is to specify the network you want to broadcast to (i.e., 192.168.1.0/24
), and use the corresponding broadcast address to send the packet, like this:
$ wakeonlan -i 192.168.1.255 aa:bb:cc:dd:ee:ff
Sending magic packet to 192.168.1.255:9 with aa:bb:cc:dd:ee:ff
The requirement for this method to work is the docker network adapter must be configured for the broadcast (see this article for more details).
The other option is easier, and the only requirement is your target machine has a static IP. In that case, you can specify the IP and MAC address and don't need to do any specific configuration to the docker network.
$ wakeonlan -i 192.168.1.10 aa:bb:cc:dd:ee:ff
Sending magic packet to 192.168.1.10:9 with aa:bb:cc:dd:ee:ff
Note: wakeonlan
uses port 9
by default, but it's not used in any case so you can use whatever port you prefer. You will see programs using 7
, 4000
, or other ports. 7
for me it's cleaner because it's usually a Discard service, but it's really not important.
Upvotes: 1
Reputation: 119
There's a mix of partially correct answers in the above comments. You do want to send your packet to port 9 on the host but:
Upvotes: 0
Reputation: 715
It seems that UDP broadcast from docker isn't being routed properly (possibly only broadcasted in the container itself, not on the host).
You can't send UDP WoL messages directly, as the device you're trying to control is 'offline' it doesn't show up in your router's ARP table and thus the direct message can't be delivered.
You may try setting (CLI) --network host
or (compose) network_mode: host
.
If you feel this may compromise security (since your container's/host network are more directly 'connected') or otherwise interferes with your container; you may create/use a separated 'WoL' container.
Upvotes: 3