Make a minimalist Ubuntu + gmsaas Docker image

Published on 2024-12-03.

Overview

Pre-requiste

Dockerfile

FROM ubuntu:22.04
# Needed to pass tzdata interactive configuration
ENV DEBIAN_FRONTEND="noninteractive" TZ="Europe/London"
# Install packages as root
RUN apt-get -y update \
&& apt-get install -y \
android-sdk \
locales \
python3 \
python3-pip \
sudo
# Set up environment variables
ENV ANDROID_HOME=/usr/lib/android-sdk
# Required by Python to use utf-8 by default
RUN locale-gen en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
# Create a non-root user
ARG USERNAME=appuser
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME
# Give the new user ownership of the Android SDK directory if needed
RUN chown -R $USERNAME:$USERNAME $ANDROID_HOME
# Switch to the non-root user
USER $USERNAME
WORKDIR /home/$USERNAME
# Install Python packages as the non-root user
RUN pip3 install --user --upgrade pip \
&& pip3 install --user virtualenv \
&& pip3 install --user gmsaas \
&& ~/.local/bin/gmsaas config set android-sdk-path $ANDROID_HOME
# Make sure the .local/bin directory is in PATH
ENV PATH="/home/$USERNAME/.local/bin:${PATH}"
CMD ["/bin/bash"]

We recommend saving the file as “Dockerfile”, without any extensions.

Build the container and start using gmsaas

We assume that you are working in the same folder where you saved your Dockerfile. Then run the following command in a terminal:

docker build --tag genymotion/gmsaas .
uuid=$(docker run --detach --tty --interactive genymotion/gmsaas)
docker exec -ti $uuid /bin/bash

You will then access the container bash terminal to pass your gmsaas commands. See gmsaas documentation for more details about gmsaas commands.

Stop the container

When done, you can stop the container with the command:

docker stop $uuid