Chasing AOSP: Using Docker to Isolate an Ubuntu 18.04 System within Modern Setup

After the initial attempt failed, I opted to install Ubuntu 22.04 as the host system. By “host system,” I mean that Ubuntu 22.04, being the latest release, isn’t fully compatible with older Android build tools (for instance, specific Python or GCC versions). Rather than downgrading the entire system, I used Docker to safely isolate an Ubuntu 18.04 environment within my modern setup—essentially creating a time machine for the terminal.

What Docker gave me:

  • A clean Ubuntu 18.04 workspace just for building AOSP
  • No messing up your main system or installing old tools globally
  • Full access to your hardware (RAM, CPU, disk) with almost zero slowdown
  • Everything happens from the command line, just how you like it

Docker vs VirtualBox: What’s the Difference?

FeatureDocker (Containers)VirtualBox (VMs)
PerformanceFast (runs on your real kernel)Slower (emulates full hardware)
Setup TimeQuick (seconds to minutes)Long (install full OS in VM)
Resource UsageLightweight (uses only what it needs)Heavy (reserves RAM, disk)
GUI SupportCLI-first (but can run GUI apps if needed)Full desktop GUI (like a separate computer)
Use CaseBest for command-line tools & dev environmentsBest for full desktop experiences

Simple Analogy:

Docker is like setting up a tool bench in a corner of your workshop.

VirtualBox is like building a whole separate room just to use a hammer.

Step-by-Step guidance:

Here’s how I proceeded, including all the error messages encountered, to install Ubuntu 18.04 within the Docker environment.

Install Docker on Ubuntu 22.04

I ran those commands:

sudo apt update
sudo apt install docker.io -y
sudo systemctl enable docker
sudo systemctl start docker

Then I added myself to the Docker group so I didn’t need to dosudo every time:

sudo usermod -aG docker $USER

Logout and log back in (or reboot) to apply group changes.

Create AOSP Build Directory

mkdir -p ~/aosp

This would be mounted into the container, so the source stays on my real disk (1TB drive).

Create a Dockerfile for Ubuntu 18.04 + AOSP tools

In a working folder:

mkdir ~/aosp-docker && cd ~/aosp-docker

Created a file called Dockerfile:

vim Dockerfile

Pasted this inside:

FROM ubuntu:18.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt update && apt install -y \
    openjdk-8-jdk \
    git-core \
    gnupg \
    flex \
    bison \
    gperf \
    build-essential \
    zip \
    curl \
    zlib1g-dev \
    gcc-multilib \
    g++-multilib \
    libc6-dev-i386 \
    lib32ncurses5-dev \
    x11proto-core-dev \
    libx11-dev \
    lib32z-dev \
    ccache \
    libgl1-mesa-dev \
    libxml2-utils \
    xsltproc \
    unzip \
    bc \
    python \
    python3 \
    rsync \
    nano \
    vim \
    x11-utils \
    android-tools-adb \
    locales

# Locale setup
RUN locale-gen en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8

# Java home
ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
ENV PATH=$JAVA_HOME/bin:$PATH

# Optional: Add ccache to path
ENV USE_CCACHE=1
ENV CCACHE_DIR=/ccache
RUN mkdir /ccache

# Default workdir
WORKDIR /aosp

Saved and exited.

Built the Docker Image

docker build -t aosp-ubuntu18 .

Ran the Container

docker run -it --rm \
  --name aosp-dev \
  -v ~/aosp:/aosp \
  -v ~/.ccache:/ccache \
  aosp-ubuntu18

Everything I did inside /aosp was persist because it’s mapped to my real ~/aosp folder.

Inside the Container

Now I was inside an Ubuntu 18.04 shell — from here I could:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

From here, go to Android’s official AOSP page…

Go to this page: https://source.android.com/docs/setup/start/requirements

Ran the following commands:

sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig
sudo apt-get update
sudo apt-get install repo
repo version

I got this error:

root@302eccb186d3:/aosp# repo version
error: command 'version' requires repo to be installed first.
         Use "repo init" to install it here.
root@302eccb186d3:/aosp# apt-get install repo
Reading package lists... Done
Building dependency tree       
Reading state information... Done
repo is already the newest version (1.12.37-3ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
root@302eccb186d3:/aosp# repo version
error: command 'version' requires repo to be installed first.
         Use "repo init" to install it here.

What’s happening?

The repo tool is actually a Python script wrapper, and the apt package just gave me the binary wrapper. But before I could run most commands like repo version, it needs to download the full tool (Python script) into my working directory using repo init.

What to do now:

repo init -u https://android.googlesource.com/platform/manifest -b android-12.0.0_r13

Then, I got this error:

root@302eccb186d3:/aosp/aosp12# repo init -u https://android.googlesource.com/platform/manifest -b android-12.0.0_r13
gpg: keybox '/root/.repoconfig/gnupg/pubring.kbx' created
gpg: /root/.repoconfig/gnupg/trustdb.gpg: trustdb created
gpg: key 16530D5E920F5C65: public key "Repo Maintainer <repo@android.kernel.org>" imported
gpg: key 67B7E448692B382C: public key "Conley Owens <cco3@android.com>" imported
gpg: Total number processed: 2
gpg:               imported: 2

Get https://gerrit.googlesource.com/git-repo/clone.bundle
Get https://gerrit.googlesource.com/git-repo
  File "/aosp/aosp12/.repo/repo/main.py", line 94
    )
    ^
SyntaxError: invalid syntax
root@302eccb186d3:/aosp/aosp12# 

Clean Start with Manually Installedrepo

mkdir -p ~/bin
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
export PATH=~/bin:$PATH
cd /aosp/aosp12
repo init -u https://android.googlesource.com/platform/manifest -b android-12.0.0_r13

Next step: Download the actual AOSP source

repo sync -j$(nproc)
ls .repo

It took more than seven hours and didn’t finish…

This isn’t normal Git behavior — especially since:

  • The rest of the 1050 repos synced successfully
  • I was on a very capable system
  • AOSP sync doesn’t usually take more than 1–2 hours total on a good connection
Ctrl + C

Error Summary:

RPC failed; HTTP 429 curl 22 The requested URL returned error: 429 Too Many Requests

This means Google’s git server rate-limited me after too many repo requests in a short time — probably from the retry loops or stuck syncs.

Delete the broken Git repo

rm -rf /aosp/aosp12/.repo/project-objects/platform/prebuilts/module_sdk/IPsec.git

Optionally, also clear its object cache (if it exists):

rm -rf /aosp/aosp12/.repo/project-objects/prebuilts/module_sdk/IPsec.git

Don’t worry — repo sync will safely re-fetch everything.

Re-sync just that repo

Then run:

repo sync prebuilts/module_sdk/IPsec

Wait for it to complete.

Final sync pass (recommended)

After that, do a final clean sync to catch any missing pieces:

repo sync -c -j4 --fail-fast --force-sync

That should wrap up my full AOSP tree download.

repo sync has finished successfully.

Leave a Reply

Your email address will not be published. Required fields are marked *