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

[🐛 Bug ]: Device data reset when docker restart

Open sandyboxy opened this issue 2 years ago • 22 comments

Operating System

Ubuntu 22.04

Docker Image

budtmo/docker-android:emulator_13.0

Expected behaviour

Hello, this is my docker-compose based on @SudhanvaManjunath post

version: '3'
services:
  android-container:
    image: budtmo/docker-android:emulator_13.0
    #deploy:
    # resources:
    #  limits:
    #   cpus: '8'
    #   memory: 10000M
    #  reservations:
    #   cpus: '8'
    #   memory: 10000M
    privileged: true
    ports:
      - 4723:4723
      - 5555:5555
    #  - 9000
      - 6080:6080
    volumes:
      - ./video-samsung_13.0:/tmp/video
    environment:
      - EMULATOR_DEVICE="Samsung Galaxy S10"
     # - APPIUM=true
      - WEB_VNC=true
     # - WEB_LOG=true
     # - WEB_LOG_PORT=9000
    devices:
      - "/dev/kvm"

Actual behaviour

When I stop docker and restart it I have a new phone with default settings and without my previous settings and data.

sandyboxy avatar Nov 09 '23 15:11 sandyboxy

I also tried to mount volumes in this way but without success:

    volumes:
      - ./android:/root/.android/
      - ./android-emulator:/root/android_emulator

sandyboxy avatar Nov 13 '23 08:11 sandyboxy

Having the same issue here. Tried it with privileged: true and the same volumes as @sandyboxy.

Lumino2 avatar Nov 13 '23 08:11 Lumino2

I solved by mounting the following volumes:

- data:/home/androidusr
- root:/root

Hope this helps!

sandyboxy avatar Nov 16 '23 13:11 sandyboxy

Thanks! @sandyboxy Here's a complete .yml file to anyone who wants to persist the data

version: '3.3'

services: docker-android: ports: - '6080:6080' - '5555:5555' - '5554:5554' privileged: true environment: - 'EMULATOR_DEVICE=Samsung Galaxy S10' - WEB_VNC=true volumes: - data:/home/androidusr - root:/root devices: - "/dev/kvm:/dev/kvm" container_name: android-container image: 'budtmo/docker-android:emulator_11.0'

volumes: data: root:

Lumino2 avatar Nov 17 '23 10:11 Lumino2

I tried restarting with the same config file, but observed in logs/device.stdout.log. Not sure if anyone here got the same issue

  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.```

llai-utexas avatar Jan 21 '24 09:01 llai-utexas

have same problem with @llai-utexas. Did you find a way?

ErcinDedeoglu avatar Jan 27 '24 20:01 ErcinDedeoglu

@ErcinDedeoglu I realize restarting the same docker container was the wrong way to keep the state. I follwed this suggestion here https://github.com/budtmo/docker-android/issues/129#issuecomment-493316051

I've found that if before stopping and rm the container I turn off the emulator phone on novnc, this issue goes away.

So what I did was using the volume mount confirguration listed above, but with a fresh docker container, while making sure the emulator was turned off in the last container, and the state was persisted

llai-utexas avatar Jan 28 '24 00:01 llai-utexas

@llai-utexas thanks a lot for your quick reply. It sounds like a lot of procedures to run for a docker container. I think this would be a maintenance failure for me. :) I found this: https://github.com/budtmo/docker-android/issues/364#issuecomment-1602755915 It says "you need to pay". If the owner (@budtmo) of repository confirm, then I'll check paid option if it is well maintained.

ErcinDedeoglu avatar Jan 28 '24 07:01 ErcinDedeoglu

@ErcinDedeoglu I saw that comment as well. I had the pro version as well. While I would not run into the sudo issue, the emulator would not boot up properly (I think sudo privilege for pro version literally means just that, it doesn't mean restart with state persisted). The only way that worked for me to persist the emulator state, was creating fresh container, for both pro and free versions

llai-utexas avatar Jan 28 '24 07:01 llai-utexas

I have managed to get the restart to work and persist the information. To do this I have created a Dockerfile that overwrites the original and restores the root user. I leave you the Dockerfile and docker-compose.yaml used in case it helps anyone.

Dockerfile

FROM budtmo/docker-android:emulator_11.0

USER root

RUN echo 'root:x:0:0:root:/root:/bin/bash' >> /etc/passwd

USER androidusr

docker-compose.yaml

version: '3.7'

services:
  android-container:
    image: budtmo/docker-android:emulator_11.0
    build: 
      context: .
    container_name: android-container
    privileged: true
    environment:
      - EMULATOR_DEVICE=Samsung Galaxy S10
      - WEB_VNC=true
    volumes:
      - data:/home/androidusr
      - root:/root
    ports:
      - "6080:6080"
    devices:
      - "/dev/kvm:/dev/kvm"
    restart: always

volumes:
  data:
  root:

bernatvadell avatar Mar 26 '24 07:03 bernatvadell

After a few days working with this image, I have continued to face some problems, they are now being fixed.

Dockerfile

FROM budtmo/docker-android:emulator_11.0

USER root

RUN echo 'root:x:0:0:root:/root:/bin/bash' >> /etc/passwd

USER androidusr

COPY run.sh /run.sh

ENTRYPOINT ["/bin/bash", "-c"]
CMD ["/run.sh"]

run.sh

#!/bin/bash
rm -rf /home/androidusr/emulator/*.lock
/home/androidusr/docker-android/mixins/scripts/run.sh

docker-compose.yaml

version: '3.7'

services:
  android-container:
    build:
      context: .
    container_name: android-container
    privileged: true
    environment:
      - EMULATOR_DEVICE=Samsung Galaxy S10
      - WEB_VNC=true
      - WEB_LOG=true
      - WEB_LOG_PORT=9000
      - VNC_PASSWORD=yRBLPq4h5bVAzDT83f6jQX
      - ENV_LOG_PATH=/var/log/
    volumes:
      - data:/home/androidusr
      - root:/root
    ports:
      - "6080:6080"
      - "9005:9000"
    devices:
      - "/dev/kvm:/dev/kvm"
    restart: always

volumes:
  data:
  root:

bernatvadell avatar Apr 05 '24 16:04 bernatvadell

same problem, after using @bernatvadell 's method, appium still fail image the log of it is helpless: INFO App - env APPIUM cannot be found, Appium is not started!

dmzrui avatar Jul 29 '24 09:07 dmzrui