1

I have the following script in python (using pychromecast):

#> cat chromecasts.py

import pychromecast
print(pychromecast.get_chromecasts())

When I run it locally, it works fine and discovers my TV with Chromecast built-in:

#> python chromecasts.py

([Chromecast('unknown', port=8009, cast_info=CastInfo(services={ServiceInfo(type='mdns', data='BRAVIA-4K-UR3-629460a23bba681edd7c4121e0f1abf0._googlecast._tcp.local.')}, uuid=UUID('629460a2-3bba-681e-dd7c-4121e0f1abf0'), model_name='BRAVIA 4K UR3', friendly_name='SONY KD-49XH8505', host='192.168.86.138', port=8009, cast_type='cast', manufacturer='Sony'))], <pychromecast.discovery.CastBrowser object at 0x107b1c2e0>)

But when I encapsulate it inside Docker container...

#> cat Dockerfile

FROM python:3

RUN pip install pychromecast

COPY . .

CMD ["python", "chromecasts.py"]

#> docker build -t rzarajczyk/chromecasts:latest .

... and run it...

#> docker run -it --rm --network=host rzarajczyk/chromecasts:latest

([], <pychromecast.discovery.CastBrowser object at 0x7f82c91d8af0>)

I get nothing. Even though I have --network=host switch. Please help! What can be wrong and how can I debug the problem?

Edit: my host environment is MacOS, but I have also run it on QNAP Container Station - with the same result.

5
  • Docker on Mac (and Windows) runs in a Linux virtual machine, so --network=host doesn't really do what you think (or want) (it connects the container to the network namespace of the virtual machine). If I try the same thing you're doing in this question on my Linux box, it works without a problem -- pychromecasts in the container is able to discover local chromecasts. I can't comment on the behavior on the QNAP.
    – larsks
    Commented Feb 19, 2022 at 14:53
  • @larks wow, this really explains a lot, but also means that there's no good solution for me. Commented Feb 20, 2022 at 7:41
  • Depending on how the discovery process works,, you may be able to forward specific ports. I'm away from my house for a few days so I can't try that myself.
    – larsks
    Commented Feb 20, 2022 at 12:08
  • @RafalZarajczyk did you find any solution to this? I am having same issues with my Windows Docker Instance. Commented Dec 3, 2022 at 1:36
  • @user2404597 no, I didn't. Chromecast auto-discovery still doesn't work for me. In my case I just realized I don't need it, because I know exactly the IP of my chromecast (my TV) - so instead or auto-discovering it, I just query the exact IP. Commented Dec 5, 2022 at 15:17

0

Browse other questions tagged or ask your own question.