Skip to content

Instantly share code, notes, and snippets.

@mattconnell
Created March 6, 2018 07:31
Show Gist options
  • Save mattconnell/4969f82c06e2478408708f9b4950b64c to your computer and use it in GitHub Desktop.
Save mattconnell/4969f82c06e2478408708f9b4950b64c to your computer and use it in GitHub Desktop.
Simplify ADB/fastboot use with Docker
#!/bin/bash
# Setup
CONTAINER="sorccu/adb"
CONTAINERNAME="adbd"
HOSTDIR="$HOME/Downloads/"
CONTDIR="/mnt/"
# Fetch latest version first.
echo "Pulling latest version of ${CONTAINER}..."
docker pull "${CONTAINER}":latest
echo
# Check for a running daemon container.
# Stop it, if found.
ISRUNNING=$(docker ps | grep -c adbd)
if [ ${ISRUNNING} -gt 0 ]; then
echo "Trying to stop ${CONTAINERNAME}..."
docker stop "${CONTAINERNAME}"
echo
sleep 2
fi
# Start a fresh daemon
echo "Starting daemon container..."
docker run --rm -d --privileged --net host -v /dev/bus/usb:/dev/bus/usb --name "${CONTAINERNAME}" "${CONTAINER}"
echo
# Tell the user how to use this.
echo "You should now be able to use adb/fastboot to talk to a device."
echo
echo "To use ADB, do something like this:"
echo "(Check your aliases!)"
echo "docker run --rm -ti --net host -v ${HOSTDIR}:${CONTDIR} ${CONTAINER} adb devices"
echo "docker run --rm -ti --net host -v ${HOSTDIR}:${CONTDIR} ${CONTAINER} adb push /tmp/hugs.mp4 /sdcard/"
echo
echo "Find more documentation here: https://hub.docker.com/r/sorccu/adb/"
echo "Find source here: https://github.com/sorccu/docker-adb"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment