Docker: docker-selsrv Selenium Server Image that uses selsrv_home Volume

selsrv image/volume

https://unityconstruct.org/media/files/docker/selsrv_home.2019-1222-1251.tar.gz

https://unityconstruct.org/media/files/docker/docker-selsrv_latest.tar.gz

 

1 - Build docker-ub1910x64-baseline

git clone --single-branch --branch "dist-amd64" https://github.com/tianon/docker-brew-ubuntu-core.git

docker build -t "docker-ub1910x64-baseline

Dockerfile

FROM scratch
ADD ubuntu-eoan-core-cloudimg-amd64-root.tar.gz /
# verify that the APT lists files do not exist
RUN [ -z "$(apt-get indextargets)" ]
# (see https://bugs.launchpad.net/cloud-images/+bug/1699913)

# a few minor docker-specific tweaks
# see https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap
RUN set -xe \
    \
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L40-L48
    && echo '#!/bin/sh' > /usr/sbin/policy-rc.d \
    && echo 'exit 101' >> /usr/sbin/policy-rc.d \
    && chmod +x /usr/sbin/policy-rc.d \
    \
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L54-L56
    && dpkg-divert --local --rename --add /sbin/initctl \
    && cp -a /usr/sbin/policy-rc.d /sbin/initctl \
    && sed -i 's/^exit.*/exit 0/' /sbin/initctl \
    \
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L71-L78
    && echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/docker-apt-speedup \
    \
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L85-L105
    && echo 'DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' > /etc/apt/apt.conf.d/docker-clean \
    && echo 'APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' >> /etc/apt/apt.conf.d/docker-clean \
    && echo 'Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";' >> /etc/apt/apt.conf.d/docker-clean \
    \
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L109-L115
    && echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/docker-no-languages \
    \
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L118-L130
    && echo 'Acquire::GzipIndexes "true"; Acquire::CompressionTypes::Order:: "gz";' > /etc/apt/apt.conf.d/docker-gzip-indexes \
    \
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L134-L151
    && echo 'Apt::AutoRemove::SuggestsImportant "false";' > /etc/apt/apt.conf.d/docker-autoremove-suggests

# make systemd-detect-virt return "docker"
# See: https://github.com/systemd/systemd/blob/aa0c34279ee40bce2f9681b496922dedbadfca19/src/basic/virt.c#L434
RUN mkdir -p /run/systemd && echo 'docker' > /run/systemd/container

CMD ["/bin/bash"]

 

2 - Build custom docker-core image

 

Dockerfile

FROM docker-ub1910x64-baseline:latest

#
# Create Volume:
# volume /var/core_home = /var/lib/docker/volumes/core_home/_data
#

# SSH SERVER
RUN apt-get update && apt-get install -y openssh-client openssh-server openssh-sftp-server
# create config dir(s)
RUN mkdir /var/run/sshd
# create password for root
RUN echo 'root:root' | chpasswd
# add user and create /home/<user>
RUN useradd -rm -s /bin/bash -g root -G sudo -u 1002 setup
# add password
RUN echo 'setup:putes' | chpasswd
# udpate ssh config to allow password login
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
# Expose ssh
EXPOSE 22
# =================================
# TOOLS
RUN apt-get install -y apt-utils htop nano
# =================================
# JAVA8
# Add JAVA repo
RUN apt-get update
RUN apt-get install -y curl software-properties-common
RUN apt-get install -y openjdk-8-jdk
# RUN apt-get update && apt-get -y install oracle-java8-installer
# =================================
# PHP7.2
RUN apt-get update
RUN apt-get install -y -q php7.2
RUN apt-cache search --names-only ^php
# =================================
#NOT USED - sudo apt-get --purge autoremove -y
#NOT USED - COPY php.ini - with custom settings
#NOT USED - COPY composer.phar
#NOT USED - COPY composer.json
# =================================

# =================================
# CLEAN
# clean apt packages and cache
RUN apt-get --purge autoremove -y && apt-get clean
# =================================
# INIT
# initial path
WORKDIR /var
CMD "/usr/sbin/sshd" && "/bin/bash"
# =================================
# DOCKER VOLUME
#  create volume: core_home=/var/core_home
#     docker volume create core_home
 

 

 

3 - Build Image to support Selenium-Server-Standalone on volume=selsrv_home

 

Dockerfile

FROM docker-core:latest

#
# volume /var/selsrv_home =
#    /var/lib/docker/volumes/selsrv_home/_data
#

# ---------------------------------
# APT UPDATE, UPGRADE
# ---------------------------------
RUN apt-get update && apt upgrade -y

# ---------------------------------
# SSH SERVER
# ---------------------------------
RUN apt-get update && apt-get install -y openssh-client openssh-server openssh-sftp-server
# create config dir(s)
RUN mkdir /var/run/sshd
# create password for root
RUN echo 'root:root' | chpasswd
# add user and create /home/<user>
RUN useradd -rm -s /bin/bash -g root -G sudo -u 1002 setup
# add password
RUN echo 'setup:putes' | chpasswd
# udpate ssh config to allow password login
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
# Expose ssh
EXPOSE 22

# ---------------------------------
# TOOLS
# ---------------------------------
RUN apt-get install -y apt-utils htop nano

# ---------------------------------
# JAVA8
# ---------------------------------
# Add JAVA repo
RUN apt-get update && apt-get install -y curl software-properties-common openjdk-8-jdk
# RUN apt-get update && apt-get -y install oracle-java8-installer

# ---------------------------------
# PHP7.2
# ---------------------------------
RUN apt-get update
RUN apt-get install -y -q php7.2
RUN apt-cache search --names-only ^php

#NOT USED - sudo apt-get --purge autoremove -y
#NOT USED - COPY php.ini - with custom settings
#NOT USED - COPY composer.phar
#NOT USED - COPY composer.json
# ---------------------------------

# ---------------------------------
# FIREFOX
#  firefox/bionic-updates,bionic-security 71.0+build5-0ubuntu0.18.04.1 amd64
#  https://github.com/mozilla/geckodriver/releases
# ---------------------------------
RUN apt-get install -y firefox

# ---------------------------------
# CHROMIUM - SNAP BROKEN WITH LOCALHOST SPEC
#  Package: chromium-browser
#  Version: 79.0.3945.79-0ubuntu0.18.04.1
#  https://snapcraft.io/install/chromium/ubuntu#install
# ---------------------------------
# SNAPD
#PENDING - test command
#RUN apt update && apt install -y snapd
#PENDING - test command
#RUN snap install chromium

# FAILS DO NOT USE
# RUN apt-get install -y chromium-browser
# FAILS DO NOT USE

#EXPOSE ????

# ---------------------------------
# OPRA - PENDING
# ---------------------------------

# ---------------------------------
# PHANTOMJS - PENDING
# ---------------------------------

# ---------------------------------
# SELENIUM-SERVER-STANDALONE
# ---------------------------------
EXPOSE 4444

# ---------------------------------
# CLEAN
# ---------------------------------
# clean apt packages and cache
RUN apt-get --purge autoremove -y && apt-get clean

# ---------------------------------
# INIT
# ---------------------------------
# initial path
WORKDIR /var/selsrv_home
#CMD ["/bin/bash" ]
#CMD "/var/selsrv_home/start-selsrv.sh" && "/bin/bash"
CMD "/usr/sbin/sshd" && "/var/selsrv_home/start-selsrv.sh"
 
# start ssh then interactive terminal ### OR  start detached  #  CMD ["/usr/sbin/sshd", "-D"]
#CMD /usr/sbin/sshd && echo "PENDING" && /bin/bash

#PENDING - test command
#CMD /usr/sbin/sshd && /bin/bash



# ---------------------------------
# DOCKER VOLUME
# ---------------------------------
##  create volume: selsrv_home=/var/selsrv_home
#     docker volume create selsrv_home
#  start container using volume selsrv_home ### ex: docker run -p 4444:4444 -p 2224:22  -v selsrv_home:/var/selsrv_home selsrv/selsrv:lts
#     docker run -p 4444:4444 -v selsrv_home:/var/selsrv_home ub1910-selsrv