budtmo / docker-android

Android in docker solution with noVNC supported and video recording
Other
9.55k stars 1.27k forks source link

[🐛 Bug ]: Device data reset when docker restart #395

Open sandyboxy opened 10 months ago

sandyboxy commented 10 months ago

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 commented 10 months ago

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

    volumes:
      - ./android:/root/.android/
      - ./android-emulator:/root/android_emulator
Lumino2 commented 10 months ago

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

sandyboxy commented 10 months ago

I solved by mounting the following volumes:

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

Hope this helps!

Lumino2 commented 10 months ago

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

version: '3.3'

services: docker-android: ports:

volumes: data: root:

llai-utexas commented 8 months ago

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.```
ErcinDedeoglu commented 8 months ago

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

llai-utexas commented 8 months ago

@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

ErcinDedeoglu commented 8 months ago

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

llai-utexas commented 8 months ago

@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

bernatvadell commented 6 months ago

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 commented 6 months ago

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:
dmzrui commented 2 months ago

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!

jamtheim commented 1 month ago

OMG, this works for persisting data! Thank you so much! Dont forget to chmod +x on the run.sh before copy.

juanbretti commented 1 month ago

OMG, this works for persisting data! Thank you so much! Dont forget to chmod +x on the run.sh before copy.

Thank you @jamtheim for the headsup. The file will end being:

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
RUN chmod +x /run.sh

ENTRYPOINT ["/bin/bash", "-c"]
CMD ["/run.sh"]
juanbretti commented 1 month ago

the log of it is helpless: INFO App - env APPIUM cannot be found, Appium is not started!

Try using this docker-compose.yaml:

version: '3.8'

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

volumes:
  data:
  root:

Notice I am adding: