docker-android icon indicating copy to clipboard operation
docker-android copied to clipboard

[🐛 Bug ]: After running command, container can not be used

Open Dominique1997 opened this issue 1 year ago • 8 comments

Operating System

Ubuntu

Docker Image

all version

Expected behaviour

When starting the container a android device comes online and can be accessed by vnc port

Actual behaviour

When starting the container a android device does not come online and can not be accessed by vnc port

Logs

_Samsung_Galaxy_S9_ANDROID_11_logs.txt

Dominique1997 avatar Jun 20 '24 10:06 Dominique1997

I am having the same issue

jorge-gbs avatar Jun 26 '24 01:06 jorge-gbs

same issue

VvLin-61 avatar Jun 27 '24 13:06 VvLin-61

same issue

> docker exec -it 823240 cat device_status
STARTING

in docker

$ emulator
INFO    | Storing crashdata in: /tmp/android-unknown/emu-crash-34.2.13.db, detection is enabled for process: 106
INFO    | Android emulator version 34.2.13.0 (build_id 11772612) (CL:N/A)
ERROR   | No AVD specified. Use '@foo' or '-avd foo' to launch a virtual device named 'foo'

$ emulator -list-avds
INFO    | Storing crashdata in: /tmp/android-unknown/emu-crash-34.2.13.db, detection is enabled for process: 136
samsung_galaxy_s10_11.0

ichinya avatar Jul 03 '24 06:07 ichinya

androidusr@95b68f435bbf:~$ docker-android start device
2024-07-03 06:11:30 INFO Emulator - Sending user behavior analytics to improve the tool
2024-07-03 06:11:32 INFO Emulator - Config file exists
2024-07-03 06:11:32 INFO Emulator - Selected device is already created
sudo: unknown user: root
sudo: unable to initialize policy plugin
Traceback (most recent call last):
  File "/usr/local/bin/docker-android", line 11, in <module>
    load_entry_point('docker-android', 'console_scripts', 'docker-android')()
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/androidusr/docker-android/cli/src/app.py", line 144, in start
    start_device()
  File "/home/androidusr/docker-android/cli/src/app.py", line 77, in start_device
    selected_device.start()
  File "/home/androidusr/docker-android/cli/src/device/emulator.py", line 160, in start
    self.change_permission()
  File "/home/androidusr/docker-android/cli/src/device/emulator.py", line 142, in change_permission
    subprocess.check_call(c, shell=True)
  File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command 'sudo chown 1300:1301 /dev/kvm' returned non-zero exit status 1.
androidusr@95b68f435bbf:~$ exit

if run root docker

PS D:\> docker exec -u0 -it 823240 docker-android start device
2024-07-03 06:12:37 INFO Emulator - Sending user behavior analytics to improve the tool
2024-07-03 06:12:37 INFO Emulator - Config file exists
2024-07-03 06:12:37 INFO Emulator - Selected device is already created
sudo: you do not exist in the passwd database
Traceback (most recent call last):
  File "/usr/local/bin/docker-android", line 11, in <module>
    load_entry_point('docker-android', 'console_scripts', 'docker-android')()
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/androidusr/docker-android/cli/src/app.py", line 144, in start
    start_device()
  File "/home/androidusr/docker-android/cli/src/app.py", line 77, in start_device
    selected_device.start()
  File "/home/androidusr/docker-android/cli/src/device/emulator.py", line 160, in start
    self.change_permission()
  File "/home/androidusr/docker-android/cli/src/device/emulator.py", line 142, in change_permission
    subprocess.check_call(c, shell=True)
  File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command 'sudo chown 1300:1301 /dev/kvm' returned non-zero exit status 1.

ichinya avatar Jul 03 '24 06:07 ichinya

PS D:\> docker exec -u0 -it 823240 chmod 777 /dev/kvm
PS D:\> docker exec -it 823240 /usr/bin/emulator -avd samsung_galaxy_s10_11.0

run emulator, but device_status not update

PS D:\> docker exec -it 823240 cat device_status
STARTING

ichinya avatar Jul 03 '24 07:07 ichinya

Same issue here when restaring a container with persistant data

jamtheim avatar Aug 22 '24 00:08 jamtheim

its problem from there https://github.com/budtmo/docker-android/blob/7064a9bc2cdfeb99bfa7ea6a1ab3cb888369df42/cli/src/device/emulator.py#L140 In first start installs rights for /dev/kvm and remove root user from system. after reboot container for /dev/kvm present old rights and no can use sudo by not exist root user.

@budtmo Can you explain why this was done? And perhaps it is worth removing the deletion of the root user in the container?

chodorenko avatar Aug 26 '24 06:08 chodorenko

Yup, I had the same/similar issues. I solved it with the following changes to my compose file.

It remaps the container user/group ids to those on the docker host, and comments out the change_permission line in the device/emulator.py file.

  • As it's using the dockerfile_inline element, it requires: Docker Compose 2.17.0 and later
  • I use an .env file alongside the compose file, with PUID and PGID vars set for the IDs of the relevant user/group on the docker host (as per linuxserver.io), and these get interpolated into the inline dockerfile on build.
services:
  android:
    build:
      dockerfile_inline: |
        FROM budtmo/docker-android:${BUILDTAG-emulator_11.0}
        ARG USERNAME=androidusr

        USER root

        # change the group and user id's to the relevant host id's
        RUN groupmod --gid ${PGID} $${USERNAME} && \
            usermod --gid ${PGID} --uid ${PUID} $${USERNAME}

        WORKDIR /home/$${USERNAME}

        # fix permissions
        RUN chown -R $${USERNAME}:$${USERNAME} /home/$${USERNAME} && \
            chown -R $${USERNAME}:$${USERNAME} /usr/lib/node_modules/appium && \
            sed -i "s/^\(\s*\)\(self\.change_permission()\)/ \1# \2/" ./docker-android/cli/src/device/emulator.py # comment out the change_permission line

        USER $${USERNAME}

tompipe avatar Apr 24 '25 17:04 tompipe