I have am using Docker inside a VM (Debian Stable). I want to run an Android emulator for x86_64 in a Docker container.
Here is how the Docker image is built:
FROM debian:stable
RUN apt-get update && apt-get install --yes curl unzip openjdk-8-jdk libqt5widgets5
RUN useradd foo --shell /bin/bash --create-home --user-group
USER foo
WORKDIR /home/foo
RUN curl --output sdk-tools-linux.zip https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip
RUN unzip sdk-tools-linux.zip && rm sdk-tools-linux.zip
RUN yes | tools/bin/sdkmanager 'system-images;android-24;default;x86_64' 'emulator' 'build-tools;26.0.1' 'platform-tools' 'platforms;android-24'
RUN echo no | tools/bin/avdmanager create avd --package 'system-images;android-24;default;x86_64' --name android-x86_64
When starting the emulator like this inside the container:
emulator/emulator -avd android-x86_64 -no-window -no-audio -no-boot-anim -no-accel -gpu off
I get the following error:
emulator: WARNING: encryption is off
emulator: WARNING: x86_64 emulation may not work without hardware acceleration!
path /home/foo/.android/avd/android-x86_64.avd/system.img.qcow2
qemu-system-x86_64: -device virtio-blk-pci,drive=system,iothread=disk-iothread,modern-pio-notify: ioeventfd is required for iothread
It seems to be related to hardware acceleration (is it?). Disregarding the purposefulness of such environment (emulator inside Docker inside a VM), is it possible to run the emulator in such context? How can I solve my problem?
Thanks,
We're using (or trying to use) this exact same scenario for automated testing.
The problem: The x86 and x86_64 emulator requires hardware acceleration. Hardware acceleration (VT-X or AMD-V) is not typically available inside a virtual environment (See: https://askubuntu.com/questions/328748/how-to-enable-nested-virtualization-in-ubuntu)
This means your best option is to use the ARM emulator, which is really slow. Running this inside Docker inside a VM will be even slower.
You can create the emulator like this:
# NOTE: Must use ARM, since x86 requires hardware acceleration, which is not available inside
# a docker container running inside a virtual machine
echo no | ${ANDROID_HOME}/tools/bin/avdmanager create avd \
--abi "armeabi-v7a" \
--device 'Nexus 4' \
--force \
--name arm_emulator \
--package "system-images;android-25;google_apis;armeabi-v7a" \
--sdcard 64M
You can then start the emulator like this:
${ANDROID_HOME}/emulator/emulator \
-avd arm_emulator \
-gpu swiftshader_indirect \
-memory 512 \
-no-audio \
-no-boot-anim \
-no-window &
Running this inside Docker on my local machine takes the emulator about 4-5 minutes to finish booting. When the Docker environment runs inside VirtualBox expect it to be even slower.
Even with this working, some commands like app installation through ADB fail because they take simply too long.
If possible, it may be a better option to start the emulator parallel to the virtual machine (e.g. on the same host) and then connect to the emulator through network.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With