google / android-emulator-container-scripts

1.82k stars 256 forks source link

What is the healthcheck of these emulators under Docker? #313

Closed gounthar closed 1 year ago

gounthar commented 1 year ago

Hi there,

First of all, thanks for this set of images, they are very useful to me. 🙏 I have a complex (to me) set of services defined in a docker-compose.yml file, and I have depends-on definition for services depending on the emulator.

For the time being, I have hardcoded sleep time in temporary services because even if docker says the emulator service is up and running, the emulator hasn't finished booting for some time...

    [...]
    emulator:
        platform: linux/amd64
        image: us-docker.pkg.dev/android-emulator-268719/images/30-google-x64:30.1.2
        restart: unless-stopped
        ports:
            - 8554:8554
            - 5555:5555
        environment:
            - ADBKEY
        devices:
            - /dev/kvm
        healthcheck:
            test: [ "CMD", "???", "???, "???" ]
            interval: 5s
            timeout: 3s
            retries: 10
            start_period: 15s
    adb-connector:
        container_name: adb-connector
        build: ./adb-connector
        privileged: true
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock:rw
        command:
            - sleep 30 && docker exec adb adb connect emulator:5555 
        depends_on:
            - adb
            - emulator
    [...]

I would like to get rid of the sleep and use a healthcheck command on the emulator container. Does the Dockerfile already defines a healthcheck? Is there any healthcheck command you think of that could help me knowing when the emulator is ready? I thought of an adb command but it's not part of the docker image.

Thank you.

gounthar commented 1 year ago
        healthcheck:
            test: [ "CMD", "/android/sdk/platform-tools/adb", " connect", "localhost:5555" ]
            interval: 5s
            timeout: 3s
            retries: 10
            start_period: 15s

Works fine for me.

gounthar commented 1 year ago

@dduportal gave me a hint. docker inspect gives me the information I was looking for:

 "Healthcheck": {
                "Test": [
                    "CMD-SHELL",
                    "/android/sdk/platform-tools/adb shell getprop dev.bootcomplete | grep \"1\""
                ],
                "Interval": 30000000000,
                "Timeout": 30000000000,
                "StartPeriod": 30000000000,
                "Retries": 3
            },