2021-03-26

Docker and Python debugging in VS Code error: timed out waiting for launcher to connect

Scenario: you have a Linux machine and you're creating a Dockerized Python app. You fire up Visual Studio Code, follow the official instructions, and eagerly hit F5 to test your app.

But nothing happens, except an error dialog after about 15 seconds:


This may be your firewall blocking connections on the docker network interface.

To confirm this, turn off your firewall, launch a debug process in VS Code, and see if the debug session starts. Repeat with the firewall on. If that fails, it's time to add rules allowing traffic for the docker interface.

First, find the subnet for your docker interface:



In this instance, you want traffic allowed through docker0 over its IP range, which in my case is 172.17.0.0/16. Yours may be different.

In a terminal, add those rules:

sudo ufw allow out on docker0 from 172.17.0.0/16
sudo ufw allow in on docker0 from 172.17.0.0/16

Reload your firewall config, and your debugging should start working.

sudo ufw reload








2021-02-12

How to Resolve Windows Host Names on your LAN from a Linux Machine

Resolving Windows host names on a LAN from a Linux machine is tricky and changes often enough that most AskUbuntu or Stack Overflow "solutions" don't work as of Feb 2021.

This method works in KDE Neon 5.20 with Kernel 5.4.0-65-generic and should work with most Ubuntu 20.x versions.

The idea is to give your Ubuntu machine your router's / DHCP server's address as a secondary DNS server.

The difficulty is that the standard /etc/resolv.conf file gets clobbered when the NetworkManager service starts. The trick is how to manage resolv.conf manually.

Prerequisites: 

  • A LAN
  • A Windows host on the LAN with default network configuration, in WORKGROUP
  • A Ubuntu 20.x machine

All of the following happens on the Ubuntu machine. The Windows host doesn't need any reconfiguration.

Steps:

  1. Tell NetworkManager not to provide DNS resolution
  2. Create your own resolv.conf

Create /etc/NetworkManager/conf.d/90-dns-none.conf file with the following content:

[main]
dns=none

Step 1.1
Restart NetworkManager
sudo systemctl reload NetworkManager

Step 2
If /etc/resolv.conf is a symlink to a systemd file (typically /run/systemd/resolve/resolv.conf or the stub file), remove that symlink.
Create a/etc/resolv.conf file like this (replace 192.168.1.1 with your router or DHCP server's actual IP address if it's different):

nameserver 127.0.0.53
nameserver 192.168.1.1

Step 2.1 
Restart the resolver 

sudo systemctl restart systemd-resolved

Then you can test like this:

$ nslookup google.com
Server:         127.0.0.53
Address:        127.0.0.53#53

Non-authoritative answer:
Name:   google.com
Address: 216.58.195.78
Name:   google.com
Address: 2607:f8b0:4005:807::200e

$ nslookup mywindowsmachine
;; Got SERVFAIL reply from 127.0.0.53, trying next server
Server:         192.168.1.1
Address:        192.168.1.1#53

Name:   mywindowsmachine
Address: 192.168.1.61
;; Got SERVFAIL reply from 127.0.0.53, trying next server


If the above still doesn't work, try installing winbind. 

sudo apt install winbind libnss-winbind