2 min read

Dev Container ADB

Sometimes when developing embedded software on a Windows machine from a containerised Linux host, i.e. within a Dev Container, it can help to talk to the embedded device using the Android Debug Bridge (ADB) but indirectly via Windows.

Latest ADB, Docker Internal

Download the latest version of the Android platform tools and unzip them somewhere. Link the adb tool to somewhere that your shell can find. Run the following from within the dev container.

wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip
unzip platform-tools-latest-linux.zip
ln -sf /path/to/platform-tools/adb ~/.local/bin/

Do not forget the final slash when sym-linking.

Now connect to the Android shell using the special host.docker.internal hostname, as follows.

adb -H host.docker.internal shell

Presto! It connects from the dev container, through the Windows ADB host to the Android device.

Explanation

The development container does not run the ADB server itself. Instead, it connects to the ADB server running on the Windows host, using host.docker.internal as the ADB hostname. The -H option overrides the default localhost; the default port remains the same 5037.

The indirect approach outlined above makes some important assumptions:

  • Linking to ~/.local/bin/ assumes that the Linux PATH carries that directory. The user’s ~/.profile typically sets up the PATH so it includes the user’s private bin if it exists.
  • The ADB client and server need the same version; connection typically fails otherwise. Make sure that adb --version gives the same answer for Linux as well as Windows. Align the versions if not already match. It might be easiest to install adb on Windows using Chocolatey and then match the same version within the Dev Container.