├── docker-run.env ├── docker-entrypoint.sh ├── wrapper_process.sh ├── logs.sh ├── shell.sh ├── docker-compose.yml ├── delete.sh ├── stop.sh ├── commit-push.sh ├── restore.sh ├── .gitignore ├── save.sh ├── clean.sh ├── Dockerfile ├── README.md ├── Makefile ├── LICENSE ├── scripts └── setup_system_certificates.sh └── run.sh /docker-run.env: -------------------------------------------------------------------------------- 1 | #### Ref: https://vsupalov.com/docker-arg-env-variable-guide/ 2 | #### Rider configuration for run.sh #### 3 | # - Use "#VOLUMES" and "#PORTS" to indicate that the variables for run.sh" 4 | # - To ignore line, use "##" (double) in the beginning, e.g. "##VOLUMES" and "##PORTS" 5 | # - To indicate that the variables for run.sh", use only one "#", e.g. "#VOLUMES" and "#PORTS" 6 | ## VOLUMES_LIST="./data:data ./workspace:workspace" 7 | 8 | #VOLUMES_LIST="data workspace" 9 | 10 | #### ---- Mongodb login/password ---- 11 | MONGO_INITDB_ROOT_USERNAME=admin 12 | MONGO_INITDB_ROOT_PASSWORD=password 13 | 14 | -------------------------------------------------------------------------------- /docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | set -e 4 | 5 | whoami 6 | 7 | env | sort 8 | 9 | echo "Inputs: $*" 10 | 11 | #### ------------------------------------------------------------------------ 12 | #### ---- Extra line added in the script to run all command line arguments 13 | #### ---- To keep the docker process staying alive if needed. 14 | #### ------------------------------------------------------------------------ 15 | set -v 16 | if [ $# -gt 0 ]; then 17 | 18 | #### 1.) Setup needed stuffs, e.g., init db etc. .... 19 | #### (do something here for preparation) 20 | exec "$@" 21 | 22 | else 23 | /bin/bash 24 | fi 25 | 26 | #tail -f /dev/null 27 | -------------------------------------------------------------------------------- /wrapper_process.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | printenv 6 | 7 | WAIT_SEC=60 8 | 9 | #e.g. /home/developer/denodo-platform-7.0/bin/denodo_platform.sh 10 | 11 | if [ "${PRODUCT_EXE}" == "" ]; then 12 | echo "*** ERROR ****: PRODUCT_EXE variable is not defined in Dockerfile or not exported!" 13 | exit 1 14 | fi 15 | 16 | if [ $# -gt 0 ]; then 17 | 18 | PROC_PATTERN="$(basename {PRODUCT_EXE})" 19 | 20 | /bin/bash -c ${PRODUCT_EXE} 21 | 22 | sleep ${WAIT_SEC} 23 | 24 | PID=`ps -elf|grep "${PROC_PATTERN}" | grep -v grep | awk '{print $4}' | head -1` 25 | 26 | #### Serveral options to make 27 | while [ "${PID}" != "" ] 28 | do 29 | echo "Process: $PID is still running" 30 | sleep ${WAIT_SEC} 31 | PID=`ps -elf|grep "${PROC_PATTERN}" | grep -v grep | awk '{print $4}' | head -1` 32 | done 33 | #wait ${PID} 34 | -------------------------------------------------------------------------------- /logs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | MY_DIR=$(dirname "$(readlink -f "$0")") 4 | 5 | if [ $# -lt 1 ]; then 6 | echo "Usage: " 7 | echo " ${0} " 8 | echo "e.g.: " 9 | echo " ${0} ls -al " 10 | fi 11 | 12 | ################################################### 13 | #### ---- Change this only to use your own ---- 14 | ################################################### 15 | ORGANIZATION=openkbs 16 | baseDataFolder="$HOME/data-docker" 17 | 18 | ################################################### 19 | #### **** Container package information **** 20 | ################################################### 21 | DOCKER_IMAGE_REPO=`echo $(basename $PWD)|tr '[:upper:]' '[:lower:]'|tr "/: " "_" ` 22 | imageTag="${ORGANIZATION}/${DOCKER_IMAGE_REPO}" 23 | 24 | ## -- transform '-' and space to '_' 25 | #instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/\-: " "_"` 26 | instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/: " "_"` 27 | 28 | echo "---------------------------------------------" 29 | echo "---- Print Log for Container for ${imageTag}" 30 | echo "---------------------------------------------" 31 | sudo docker logs ${instanceName} 32 | 33 | 34 | -------------------------------------------------------------------------------- /shell.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | MY_DIR=$(dirname "$(readlink -f "$0")") 4 | 5 | if [ $# -lt 1 ]; then 6 | echo "Usage: " 7 | echo " ${0} " 8 | echo "e.g.: " 9 | echo " ${0} ls -al " 10 | fi 11 | 12 | ################################################### 13 | #### ---- Change this only to use your own ---- 14 | ################################################### 15 | ORGANIZATION=openkbs 16 | baseDataFolder="$HOME/data-docker" 17 | 18 | ################################################### 19 | #### **** Container package information **** 20 | ################################################### 21 | DOCKER_IMAGE_REPO=`echo $(basename $PWD)|tr '[:upper:]' '[:lower:]'|tr "/: " "_" ` 22 | imageTag="${ORGANIZATION}/${DOCKER_IMAGE_REPO}" 23 | 24 | ## -- transform '-' and space to '_' 25 | #instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/\-: " "_"` 26 | instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/: " "_"` 27 | 28 | echo "---------------------------------------------" 29 | echo "---- shell into the Container for ${imageTag}" 30 | echo "---------------------------------------------" 31 | 32 | sudo docker exec -it $(sudo docker ps -a |grep ${instanceName} |awk '{print $1;}') /bin/bash 33 | 34 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.3' 2 | 3 | # Usage: 4 | # docker stack deploy -c stack.yml mongo 5 | # or 6 | # docker-compose -f stack.yml up 7 | 8 | services: 9 | 10 | mongo: 11 | image: mongo 12 | restart: always 13 | container_name: mongo-docker 14 | environment: 15 | MONGO_INITDB_ROOT_USERNAME: mongoadmin 16 | MONGO_INITDB_ROOT_PASSWORD: mongoadmin 17 | #MONGODB_AUTH_DATABASE: admin 18 | ports: 19 | - "27017:27017" 20 | volumes: 21 | - ./workspace:/workspace 22 | - type: volume 23 | source: mongodb_data_volume 24 | target: /data/db 25 | 26 | mongo-express: 27 | image: mongo-express 28 | container_name: mongo-express 29 | restart: always 30 | ports: 31 | - "28081:8081" 32 | environment: 33 | ME_CONFIG_MONGODB_SERVER: mongo 34 | ME_CONFIG_BASICAUTH_USERNAME: admin 35 | ME_CONFIG_BASICAUTH_PASSWORD: changeme 36 | #ME_CONFIG_MONGODB_AUTH_DATABASE: admin 37 | ME_CONFIG_MONGODB_ADMINUSERNAME: mongoadmin 38 | ME_CONFIG_MONGODB_ADMINPASSWORD: mongoadmin 39 | ME_CONFIG_MONGODB_URL: mongo://mongoadmin:mongoadmin@mongo:27017/ 40 | depends_on: 41 | - mongo 42 | 43 | volumes: 44 | mongodb_data_volume: 45 | driver: local 46 | 47 | -------------------------------------------------------------------------------- /delete.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | ORGANIZATION=${ORGANIZATION:-openkbs} 4 | PROJECT=${PROJECT:-myproject} 5 | APPLICATION_NAME=${PWD##*/} 6 | APP_VERSION=${APP_VERSION:-1.0.0} 7 | 8 | ## Base image to build this container 9 | FROM_BASE=${FROM_BASE:-centos:8} 10 | imageTag=${imageTag:-"${ORGANIZATION}/${APPLICATION_NAME}"} 11 | 12 | ## Docker Registry (Private Server) 13 | #REGISTRY_IMAGE=${REGISTRY_HOST}/${imageTag} 14 | VERSION=${APP_VERSION}-$(date +%Y%m%d) 15 | 16 | ################################################### 17 | #### ---- Top-level build-arg arguments ---- 18 | ################################################### 19 | MY_DIR=$(dirname "$(readlink -f "$0")") 20 | 21 | ################################################### 22 | #### ---- Change this only to use your own ---- 23 | ################################################### 24 | baseDataFolder="$HOME/data-docker" 25 | 26 | ################################################### 27 | #### **** Container package information **** 28 | ################################################### 29 | 30 | ## -- transform '-' and space to '_' 31 | #instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/\-: " "_"` 32 | instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/: " "_"` 33 | 34 | echo "---------------------------------------------" 35 | echo "---- Print Log for Container for ${imageTag}" 36 | echo "---------------------------------------------" 37 | #sudo docker rm  -f $(docker ps 2>&1 | grep "reasoner-docker" | awk '{print $1}') 38 | sudo docker rm  -f ${instanceName} 39 | -------------------------------------------------------------------------------- /stop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | MY_DIR=$(dirname "$(readlink -f "$0")") 4 | 5 | if [ $# -lt 1 ]; then 6 | echo "Usage: " 7 | echo " ${0} " 8 | echo "e.g.: " 9 | echo " ${0} ls -al " 10 | fi 11 | 12 | ################################################### 13 | #### ---- Change this only to use your own ---- 14 | ################################################### 15 | ORGANIZATION=openkbs 16 | baseDataFolder="$HOME/data-docker" 17 | 18 | ################################################### 19 | #### **** Container package information **** 20 | ################################################### 21 | DOCKER_IMAGE_REPO=`echo $(basename $PWD)|tr '[:upper:]' '[:lower:]'|tr "/: " "_" ` 22 | imageTag="${ORGANIZATION}/${DOCKER_IMAGE_REPO}" 23 | 24 | ################################################### 25 | #### ---- Mostly, you don't need change below ---- 26 | ################################################### 27 | function cleanup() { 28 | containerID=`sudo docker ps -a|grep "${instanceName}" | awk '{print $1}'` 29 | # if [ ! "`sudo docker ps -a|grep ${instanceName}`" == "" ]; then 30 | if [ "${containerID}" != "" ]; then 31 | sudo docker rm -f ${containerID} 32 | fi 33 | } 34 | 35 | ## -- transform '-' and space to '_' 36 | #instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/\-: " "_"` 37 | instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/: " "_"` 38 | 39 | echo "---------------------------------------------" 40 | echo "---- stop a Container for ${imageTag}" 41 | echo "---------------------------------------------" 42 | 43 | cleanup 44 | 45 | 46 | -------------------------------------------------------------------------------- /commit-push.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Reference: 4 | # - https://docs.docker.com/engine/userguide/containers/dockerimages/ 5 | # - https://docs.docker.com/engine/reference/commandline/commit/ 6 | # docker push [OPTIONS] NAME[:TAG] 7 | # - https://docs.docker.com/engine/reference/commandline/push/ 8 | # docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] 9 | 10 | echo "Usage: " 11 | echo " ${0} [] []" 12 | echo "e.g." 13 | echo " ${0} \"initial updates\" \"openkbs/docker-project-tempalte\" \"1.0.0\" " 14 | echo "" 15 | echo "-------------------------------------" 16 | echo "-- Make sure you do login first: --" 17 | echo "-- To login:" 18 | echo " docker login" 19 | echo "-------------------------------------" 20 | echo 21 | 22 | ORGANIZATION=${ORGANIZATION:-openkbs} 23 | 24 | comment=${1:-Update with the latest changes: `date`} 25 | 26 | ################################################### 27 | #### **** Container package information **** 28 | ################################################### 29 | DOCKER_IMAGE_REPO=`echo $(basename $PWD)|tr '[:upper:]' '[:lower:]'|tr "/: " "_" ` 30 | imageTag=${2:-"${ORGANIZATION}/${DOCKER_IMAGE_REPO}"} 31 | imageVersion=${3:-latest} 32 | 33 | docker ps -a 34 | 35 | containerID=`docker ps |grep "${imageTag} "|awk '{print $1}'` 36 | echo "containerID=$containerID" 37 | 38 | #docker tag ${imageTag} ${imageTag}:latest 39 | 40 | #docker commit -m "$comment" ${containerID} ${imageTag}:latest 41 | #docker push ${imageTag}:latest 42 | 43 | echo docker commit -m "$comment" ${containerID} ${imageTag}:${imageVersion} 44 | echo docker push ${imageTag}:${imageVersion} 45 | -------------------------------------------------------------------------------- /restore.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | MY_DIR=$(dirname "$(readlink -f "$0")") 4 | 5 | if [ $# -lt 1 ]; then 6 | echo "Usage: " 7 | echo " ${0} [Different tgz Docker Image file]" 8 | echo "e.g.: " 9 | echo " ${0} " 10 | fi 11 | 12 | ################################################### 13 | #### ---- Change this only to use your own ---- 14 | ################################################### 15 | ORGANIZATION=openkbs 16 | 17 | ################################################### 18 | #### **** Container package information **** 19 | ################################################### 20 | DOCKER_IMAGE_REPO=`echo $(basename $PWD)|tr '[:upper:]' '[:lower:]'|tr "/: " "_" ` 21 | imageTag="${ORGANIZATION}/${DOCKER_IMAGE_REPO}" 22 | 23 | ################################################### 24 | #### ---- Mostly, you don't need change below ---- 25 | ################################################### 26 | ## -- transform '-' and space to '_' 27 | #instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/\-: " "_"` 28 | instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/: " "_"` 29 | 30 | TGZ_DOCKER_IMAGE=${1:-${instanceName}.tgz} 31 | 32 | function restore() { 33 | if [ ! -s ${TGZ_DOCKER_IMAGE} ]; then 34 | echo "*** ERROR ***: Can't find image (*.tgz or tar.gz) file: Can't continue! Abort!" 35 | exit 1 36 | fi 37 | gunzip -c ${TGZ_DOCKER_IMAGE} | docker load 38 | sudo docker images | grep ${TGZ_DOCKER_IMAGE%.tgz} 39 | } 40 | 41 | echo "---------------------------------------------" 42 | echo "---- SAVE a Container for ${imageTag}" 43 | echo "---------------------------------------------" 44 | 45 | restore 46 | 47 | 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | 106 | *mongodb-persistence/ 107 | *deb.* 108 | *deb 109 | -------------------------------------------------------------------------------- /save.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | MY_DIR=$(dirname "$(readlink -f "$0")") 4 | 5 | if [ $# -lt 1 ]; then 6 | echo "Usage: " 7 | echo " ${0} " 8 | echo "e.g.: " 9 | echo " ${0} " 10 | fi 11 | 12 | ################################################### 13 | #### ---- Change this only to use your own ---- 14 | ################################################### 15 | ORGANIZATION=openkbs 16 | 17 | ################################################### 18 | #### **** Container package information **** 19 | ################################################### 20 | DOCKER_IMAGE_REPO=`echo $(basename $PWD)|tr '[:upper:]' '[:lower:]'|tr "/: " "_" ` 21 | imageTag="${ORGANIZATION}/${DOCKER_IMAGE_REPO}" 22 | imageTag=${1:-$imageTag} 23 | 24 | IMAGE_NAME=${imageTag%:*} 25 | IMAGE_VERSION=${imageTag#*:} 26 | if [ "$IMAGE_VERSION" = "" ]; then 27 | # -- patch in the image version 28 | imageTag="${IMAGE_NAME}:latest" 29 | fi 30 | ################################################### 31 | #### ---- Mostly, you don't need change below ---- 32 | ################################################### 33 | ## -- transform '-' and space to '_' 34 | #instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/\-: " "_"` 35 | instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/: " "_"` 36 | 37 | TGZ_DOCKER_IMAGE=${instanceName}.tgz 38 | 39 | function save() { 40 | lookupImage=`sudo docker images ${imageTag} | grep ${imageTag} | awk '{print $1}'` 41 | if [ "$lookupImage" = "" ]; then 42 | echo "*** ERROR ***: Can't find Docker image (${imageTag}): Can't continue! Abort!" 43 | exit 1 44 | fi 45 | sudo docker save ${imageTag} | gzip > ${TGZ_DOCKER_IMAGE} 46 | ls -al ${TGZ_DOCKER_IMAGE} 47 | } 48 | 49 | echo "---------------------------------------------" 50 | echo "---- SAVE a Container for ${imageTag}" 51 | echo "---------------------------------------------" 52 | 53 | save 54 | 55 | 56 | -------------------------------------------------------------------------------- /clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | MY_DIR=$(dirname "$(readlink -f "$0")") 4 | 5 | if [ $# -lt 1 ]; then 6 | echo "------------- Clean up both Container and Images -------------" 7 | echo "Usage: " 8 | echo " ${0} []" 9 | echo "e.g.: " 10 | echo " ${0} tensorflow-python3-jupyter " 11 | echo " ${0} " 12 | echo " (empty argument will use default the current git container name to clean up)" 13 | fi 14 | 15 | ################################################### 16 | #### ---- Change this only to use your own ---- 17 | ################################################### 18 | ORGANIZATION=openkbs 19 | baseDataFolder="$HOME/data-docker" 20 | 21 | ################################################### 22 | #### **** Container package information **** 23 | ################################################### 24 | DOCKER_IMAGE_REPO=`echo $(basename $PWD)|tr '[:upper:]' '[:lower:]'|tr "/: " "_" ` 25 | imageTag="${ORGANIZATION}/${DOCKER_IMAGE_REPO}" 26 | 27 | ## -- transform '-' and space to '_' 28 | #instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/\-: " "_"` 29 | instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/: " "_"` 30 | 31 | echo "---------------------------------------------" 32 | echo "---- Clean up the Container for ${imageTag}" 33 | echo "---------------------------------------------" 34 | 35 | if [ $1 ]; then 36 | imageTag="$1" 37 | fi 38 | 39 | containers=`docker ps -a | grep ${imageTag} | awk '{print $1}' ` 40 | 41 | if [ $containers ]; then 42 | docker rm -f $containers 43 | fi 44 | 45 | for IMAGE_ID in `docker images -a | grep ${imageTag} | awk '{print $3}' `; do 46 | children=$(docker images --filter since=${IMAGE_ID} -q) 47 | if [[ ! $children == *"No such image"* ]]; then 48 | id=$(docker inspect --format='{{.Id}} {{.Parent}}' $children |cut -d':' -f2|cut -c-12) 49 | if [ "$id" != "" ]; then 50 | docker rmi -f $id 51 | fi 52 | fi 53 | done 54 | 55 | 56 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openkbs/jdk11-mvn-py3-x11 2 | 3 | MAINTAINER DrSnowbird "DrSnowbird@openkbs.org" 4 | 5 | #### ---- Build Specification ---- 6 | # Metadata params 7 | ARG BUILD_DATE=${BUILD_DATE:-`date`} 8 | ARG VERSION=${VERSION:-} 9 | ARG VCS_REF=${VCS_REF:-} 10 | 11 | #### ---- Product Specifications ---- 12 | ENV PRODUCT=${PRODUCT:-"compass"} 13 | ENV PRODUCT_VERSION=${PRODUCT_VERSION:-1.32.0} 14 | ENV PRODUCT_DIR=${PRODUCT_DIR} 15 | ENV PRODUCT_EXE=${PRODUCT_EXE:-mongodb-compass} 16 | 17 | 18 | #### -------------------------- 19 | #### ---- Install Product ----: 20 | #### -------------------------- 21 | # https://downloads.mongodb.com/compass/mongodb-compass_1.32.0_amd64.deb 22 | ARG PRODUCT_URL=https://downloads.mongodb.com/${PRODUCT}/mongodb-${PRODUCT}_${PRODUCT_VERSION}_amd64.deb 23 | RUN sudo apt-get update -y && \ 24 | sudo apt-get install -y libsecret-1-0 libgconf-2-4 libnss3 && \ 25 | echo ">>> PRODUCT_URL:${PRODUCT_URL}" && \ 26 | sudo wget -q --no-check-certificate ${PRODUCT_URL} && \ 27 | sudo dpkg -i $(basename ${PRODUCT_URL}) && \ 28 | sudo rm -f $(basename ${PRODUCT_URL}) 29 | 30 | #### ---- Plugin for Compass ---- #### 31 | #RUN wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash && \ 32 | RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash 33 | 34 | RUN export NVM_DIR="$HOME/.nvm" && \ 35 | sudo chown -R ${USER}:${USER} ${HOME} && \ 36 | chmod +x .nvm/nvm.sh && $NVM_DIR/nvm.sh && \ 37 | #nvm install stable && \ 38 | #npm install -g khaos && \ 39 | mkdir -p ${HOME}/.mongodb/${PRODUCT}-community/plugins 40 | 41 | #cd ${HOME}/.mongodb/${PRODUCT}-community/plugins && khaos create mongodb-js/compass-plugin ./${USER}-plugin && \ 42 | #cd ${HOME}/.mongo/compass/plugins 43 | 44 | #### --- Copy Entrypoint script in the container ---- #### 45 | COPY ./docker-entrypoint.sh / 46 | 47 | #### ------------------------ 48 | #### ---- user: Non-Root ---- 49 | #### ------------------------ 50 | 51 | #### --- Enterpoint for container ---- #### 52 | USER ${USER_NAME} 53 | WORKDIR ${HOME} 54 | 55 | #ENTRYPOINT ["/docker-entrypoint.sh"] 56 | 57 | CMD ["/usr/bin/mongodb-compass", "--no-sandbox"] 58 | 59 | #### (Test only) 60 | #CMD ["/usr/bin/firefox"] 61 | 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mongodb-Compass 1.32 + OpenJDK Java 11 + Maven 3.8 + Python 3.8 + pip 21 + node 16 + npm 7 + Gradle 7 2 | 3 | [![](https://images.microbadger.com/badges/image/openkbs/mongodb-compasss-docker.svg)](https://microbadger.com/images/openkbs/mongodb-compasss-docker "Get your own image badge on microbadger.com") [![](https://images.microbadger.com/badges/version/openkbs/mongodb-compasss-docker.svg)](https://microbadger.com/images/openkbs/mongodb-compasss-docker "Get your own version badge on microbadger.com") 4 | 5 | # Components 6 | * [Mongodb-Compass](https://docs.mongodb.com/compass) v 1.32.0 7 | * [Base Container Image: openkbs/jdk11-mvn-py3](https://github.com/DrSnowbird/jdk11-mvn-py3) 8 | * [Base Components: OpenJDK, Python 3, PIP, Node/NPM, Gradle, Maven, etc.](https://github.com/DrSnowbird/jdk11-mvn-py3#components) 9 | * Other tools: git wget unzip vim python python-setuptools python-dev python-numpy 10 | 11 | # Build (Do this First!) 12 | ``` 13 | make build 14 | ``` 15 | 16 | # Run 17 | To bring up X-11 Desktop of Mongodb-Compass: 18 | ``` 19 | ./run.sh 20 | ``` 21 | 22 | # Run with MongoDB together 23 | You can run Compass DB GUI and local MongoDB (as test database) 24 | 1. Bring up 'mongodb-docker' 25 | ``` 26 | docker-compose -f ./docker-compose up -d mongodb-docker 27 | ``` 28 | 2. Use the Mongodb-Compass to connect to Mongodb-docker 29 | The default password for local MongoDB: 30 | ``` 31 | MONGO_INITDB_ROOT_USERNAME: mongoadmin 32 | MONGO_INITDB_ROOT_PASSWORD: mongoadmin 33 | ``` 34 | # (Optional) Run MongoDB with Mongo-Express (Web-based UI) 35 | You can use both Mongodb-Compass (X11 Desktop App) and Mongo-Express (Web UI) at the same! 36 | ``` 37 | docker-compose up -d 38 | ``` 39 | Then, use your web-browser to go to: 40 | ``` 41 | http://0.0.0.0:28081/ 42 | (login/password: admin/changeme) 43 | ``` 44 | # References & Resources 45 | * [**Mongodb Document**](https://docs.mongodb.com/) 46 | * [Mongodb Compass (import/export)](https://docs.mongodb.com/compass/master/import-export/) 47 | 48 | # See also 49 | * [openkbs/mongo-docker](https://github.com/DrSnowbird/mongo-docker) 50 | * [MySQL Workbench for MySQL Database Server Docker at openkbs/mysql-workbench](https://hub.docker.com/r/openkbs/mysql-workbench/) 51 | * [Sqlectron SQL GUI at openkbs/sqlectron-docker](https://hub.docker.com/r/openkbs/sqlectron-docker/) 52 | * [Mysql-Workbench at openkbs/mysql-workbench](https://hub.docker.com/r/openkbs/mysql-workbench/) 53 | * [PgAdmin4 for PostgreSQL at openkbs/pgadmin-docker](https://hub.docker.com/r/openkbs/pgadmin-docker/) 54 | 55 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------------------------------- 2 | # login first (Registry: e.g., hub.docker.io, registry.localhost:5000, etc.) 3 | # a.) docker login 4 | # or 5 | # b.) sudo docker login -p FpXM6Qy9vVL5kPeoefzxwA-oaYb-Wpej2iXTwV7UHYs -e unused -u unused docker-registry-default.openkbs.org 6 | # e.g. (using Openshift) 7 | # oc process -f ./files/deployments/template.yml -v API_NAME=$(REGISTRY_IMAGE) > template.active 8 | # 9 | # to run: 10 | # make [ APP_VERSION=<...> DOCKER_NAME=<...> REGISTRY_HOST=<...> ] 11 | # example: 12 | # make build 13 | # make up 14 | # make down 15 | # ------------------------------------------------------------------------------------------------------- 16 | 17 | SHELL := /bin/bash 18 | 19 | BASE_IMAGE := $(BASE_IMAGE) 20 | 21 | ## -- To Check syntax: 22 | # cat -e -t -v Makefile 23 | 24 | # The name of the container (default is current directory name) 25 | #DOCKER_NAME := $(shell echo $${PWD\#\#*/}) 26 | DOCKER_NAME := $(shell echo $${PWD\#\#*/}|tr '[:upper:]' '[:lower:]'|tr "/: " "_" ) 27 | 28 | ORGANIZATION=$(shell echo $${ORGANIZATION:-openkbs}) 29 | APP_VERSION=$(shell echo $${APP_VERSION:-latest}) 30 | imageTag=$(ORGANIZATION)/$(DOCKER_NAME) 31 | 32 | ## Docker Registry (Private Server) 33 | REGISTRY_HOST= 34 | #REGISTRY_HOST=$(shell echo $${REGISTRY_HOST:-localhost:5000}) 35 | REGISTRY_IMAGE=$(REGISTRY_HOST)/$(ORGANIZATION)/$(DOCKER_NAME) 36 | 37 | #VERSION?="$(APP_VERSION)-$$(date +%Y%m%d)" 38 | VERSION?="$(APP_VERSION)" 39 | 40 | ## -- Uncomment this to use local Registry Host -- 41 | DOCKER_IMAGE := $(ORGANIZATION)/$(DOCKER_NAME) 42 | 43 | ## -- To Check syntax: 44 | # cat -e -t -v Makefile 45 | 46 | # -- example -- 47 | #VOLUME_MAP := "-v $${PWD}/data:/home/developer/data -v $${PWD}/workspace:/home/developer/workspace" 48 | VOLUME_MAP := 49 | 50 | # -- Local SAVE of image -- 51 | IMAGE_EXPORT_PATH := "$${PWD}/archive" 52 | 53 | # { no, on-failure, unless-stopped, always } 54 | RESTART_OPTION := always 55 | 56 | SHA := $(shell git describe --match=NeVeRmAtCh --always --abbrev=40 --dirty=*) 57 | 58 | TIME_START := $(shell date +%s) 59 | 60 | .PHONY: clean rmi build push pull up down run stop exec 61 | 62 | clean: 63 | $(DOCKER_NAME) $(DOCKER_IMAGE):$(VERSION) 64 | 65 | default: build 66 | 67 | build-time: 68 | docker build \ 69 | --build-arg BASE_IMAGE="$(BASE_IMAGE)" \ 70 | --build-arg CIRCLE_SHA1="$(SHA)" \ 71 | --build-arg version=$(VERSION) \ 72 | --build-arg VCS_REF=`git rev-parse --short HEAD` \ 73 | --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ 74 | -t $(DOCKER_IMAGE):$(VERSION) . 75 | 76 | build-rm: 77 | docker build --force-rm --no-cache \ 78 | -t $(DOCKER_IMAGE):$(VERSION) . 79 | 80 | build: 81 | docker build \ 82 | -t $(DOCKER_IMAGE):$(VERSION) . 83 | docker images | grep $(DOCKER_IMAGE) 84 | @echo ">>> Total Dockder images Build using time in seconds: $$(($$(date +%s)-$(TIME_START))) seconds" 85 | 86 | push: 87 | docker commit -m "$comment" ${containerID} ${imageTag}:$(VERSION) 88 | docker push $(DOCKER_IMAGE):$(VERSION) 89 | 90 | docker tag $(imageTag):$(VERSION) $(REGISTRY_IMAGE):$(VERSION) 91 | #docker tag $(imageTag):latest $(REGISTRY_IMAGE):latest 92 | docker push $(REGISTRY_IMAGE):$(VERSION) 93 | #docker push $(REGISTRY_IMAGE):latest 94 | @if [ ! "$(IMAGE_EXPORT_PATH)" = "" ]; then \ 95 | mkdir -p $(IMAGE_EXPORT_PATH); \ 96 | docker save $(REGISTRY_IMAGE):$(VERSION) | gzip > $(IMAGE_EXPORT_PATH)/$(DOCKER_NAME)_$(VERSION).tar.gz; \ 97 | fi 98 | 99 | pull: 100 | @if [ "$(REGISTRY_HOST)" = "" ]; then \ 101 | docker pull $(DOCKER_IMAGE):$(VERSION) ; \ 102 | else \ 103 | docker pull $(REGISTRY_IMAGE):$(VERSION) ; \ 104 | fi 105 | 106 | ## -- deployment mode (daemon service): -- ## 107 | up: 108 | bin/auto-config-all.sh 109 | docker-compose up -d 110 | docker ps | grep $(DOCKER_IMAGE) 111 | @echo ">>> Total Dockder images Build using time in seconds: $$(($$(date +%s)-$(TIME_START))) seconds" 112 | 113 | down: 114 | docker-compose down 115 | docker ps | grep $(DOCKER_IMAGE) 116 | @echo ">>> Total Dockder images Build using time in seconds: $$(($$(date +%s)-$(TIME_START))) seconds" 117 | 118 | down-rm: 119 | docker-compose down -v --rmi all --remove-orphans 120 | docker ps | grep $(DOCKER_IMAGE) 121 | @echo ">>> Total Dockder images Build using time in seconds: $$(($$(date +%s)-$(TIME_START))) seconds" 122 | 123 | ## -- dev/debug -- ## 124 | run: 125 | bin/auto-config-all.sh 126 | ./run.sh 127 | docker ps | grep $(DOCKER_IMAGE) 128 | 129 | #docker run --name=$(DOCKER_NAME) --restart=$(RESTART_OPTION) $(VOLUME_MAP) $(DOCKER_IMAGE):$(VERSION) 130 | 131 | stop: 132 | docker stop --name=$(DOCKER_NAME) 133 | 134 | status: 135 | docker ps | grep $(DOCKER_NAME) 136 | 137 | rmi: 138 | docker rmi $$(docker images -f dangling=true -q) 139 | 140 | exec: 141 | docker-compose exec $(DOCKER_NAME) /bin/bash 142 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2022 Ray Y. Sheu, Ph.D. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /scripts/setup_system_certificates.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | env|sort 4 | whoami 5 | id 6 | 7 | #### Assumptions: 8 | # 0. Run this file using 'root' 9 | # 1. Host certificates need to map inside the Container as: /certificates 10 | # 2. Container OS: Ubuntu/Debian, CentOS/Redhat, Alpine, or unknown 11 | # 3. Certificates' file name extensions: *.crt, *.pem 12 | 13 | #### ---- Usage ---- #### 14 | function usage() { 15 | echo "Usage setup_system_certificates -d [ -h | --help]" 16 | } 17 | 18 | #### ---- Usage ---- #### 19 | ORIG_ARGS="$*" 20 | SHORT="hd:i:" 21 | LONG="help,certificates_dir:,certificates_install_dir:" 22 | 23 | # $@ is all command line parameters passed to the script. 24 | # -o is for short options like -v 25 | # -l is for long options with double dash like --version 26 | # the comma separates different long options 27 | # -a is for long options with single dash like -version 28 | #OPTIONS=$(getopt --options ${SHORT} --longoptions ${LONG} --name "$0" -a -- "$@") 29 | OPTIONS=$(getopt -o ${SHORT} -l ${LONG} --name "$0" -a -- "$@") 30 | 31 | if [[ $? != 0 ]]; then 32 | echo "Arguments Parsing Error! Abort!" 33 | exit 1 34 | fi 35 | eval set -- "${OPTIONS}" 36 | 37 | ## Default /certificates 38 | SOURCE_CERTIFICATES_DIR=${SOURCE_CERTIFICATES_DIR:-/certificates} 39 | CERTITICATES_INSTALL_DIR= 40 | 41 | while true; do 42 | case "$1" in 43 | -h|--help) 44 | usage "Usage setup_system_certificates -d [ -h | --help]" 45 | ;; 46 | -d|--certificates_dir) 47 | shift 48 | SOURCE_CERTIFICATES_DIR=$1 49 | echo -e ">>> SOURCE_CERTIFICATES_DIR=$SOURCE_CERTIFICATES_DIR" 50 | ;; 51 | -i|--certificates_install_dir) 52 | shift 53 | CERTITICATES_INSTALL_DIR=$1 54 | echo -e ">>> CERTITICATES_INSTALL_DIR=$CERTITICATES_INSTALL_DIR" 55 | ;; 56 | --) 57 | shift 58 | break 59 | ;; 60 | *) 61 | echo "===================================" 62 | echo "*****: input args error" 63 | echo ">>> Input args: $ORIG_ARGS" 64 | echo ">>> Abort now!" 65 | echo "===================================" 66 | exit 3 67 | ;; 68 | esac 69 | shift 70 | done 71 | 72 | echo "===================================" 73 | echo "ORIGINAL INPUT >>>>>>>>>>:" 74 | echo ">>> Input args: $ORIG_ARGS" 75 | echo "===================================" 76 | 77 | 78 | echo -e ">>> ===================================" 79 | echo -e ">>> OS Information:" 80 | echo -e ">>> ===================================" 81 | cat /etc/*rel* 82 | echo -e ">>> ===================================" 83 | 84 | echo -e ">>> ls command: `which ls`" 85 | 86 | if [ ! -s ${SOURCE_CERTIFICATES_DIR} ]; then 87 | echo -e ">>> **************************************************************************************" 88 | echo -e ">>> ERROR: SOURCE_CERTIFICATES_DIR: ${SOURCE_CERTIFICATES_DIR}: NOT Existing/Found! Abort!" 89 | echo -e ">>> **************************************************************************************" 90 | exit 1 91 | else 92 | echo -e ">>> SOURCE_CERTIFICATES_DIR:" 93 | $sudo ls -al ${SOURCE_CERTIFICATES_DIR} 94 | fi 95 | 96 | #### ---------------------------------------------------------------------------------------------------------------------------------- #### 97 | #### ---- (ref: https://stackoverflow.com/questions/59895/get-the-source-directory-of-a-bash-script-from-within-the-script-itself) 98 | #### ---------------------------------------------------------------------------------------------------------------------------------- #### 99 | function findMyAbsDir() { 100 | SOURCE="${BASH_SOURCE[0]}" 101 | while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink 102 | DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" 103 | SOURCE="$(readlink "$SOURCE")" 104 | [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located 105 | done 106 | MY_ABS_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" 107 | } 108 | # findMyAbsDir 109 | MY_ABS_DIR=$(dirname "$(readlink -f "$0")") 110 | 111 | 112 | #### ------------------------------------------------- 113 | #### OS_TYPE= 114 | #### >>> 115 | #### 0: OS_TYPE_NOT_FOUND 116 | #### 1: ubuntu/debian 117 | #### 2: centos/redhat/fedora 118 | #### 3: alpine 119 | #### 4: others 120 | #### ------------------------------------------------- 121 | OS_TYPE=0 122 | 123 | REPO_CONF=/etc/apt/apt.conf 124 | ETC_ENV=/etc/environment 125 | APT_PATH=/usr/bin/apt 126 | YUM_PATH=/usr/bin/yum 127 | 128 | OS_NAME= 129 | function detectOS_alt() { 130 | OS_NAME="`which yum`" 131 | if [ -s ${APT_PATH} ]; then 132 | OS_NAME="ubuntu" 133 | OS_TYPE=1 134 | elif [ -s ${YUM_PATH} ]; then 135 | OS_NAME="centos" 136 | OS_TYPE=2 137 | fi 138 | } 139 | 140 | 141 | function detectOS() { 142 | OS_NAME="`cat /etc/os-release |grep -i '^id='|cut -d'=' -f2|cut -d'"' -f2 | tr '[:upper:]' '[:lower:]'`" 143 | #OS_NAME="`cat /etc/os-release | grep -i '^NAME=\"Ubuntu\"' | awk -F= '{print $2}' | tr '[:upper:]' '[:lower:]' |sed 's/"//g' `" 144 | if [ "${OS_NAME}" == "" ]; then 145 | detectOS_alt 146 | fi 147 | case ${OS_NAME} in 148 | ubuntu*|debian*) 149 | OS_TYPE=1 150 | REPO_CONF=/etc/apt/apt.conf 151 | ETC_ENV=/etc/environment 152 | ;; 153 | centos*|fedora*|redhat*) 154 | OS_TYPE=2 155 | REPO_CONF=/etc/yum.conf 156 | ETC_ENV=/etc/environment 157 | ;; 158 | alpine*) 159 | OS_TYPE=3 160 | REPO_CONF=/etc/conf.d 161 | ETC_ENV=/etc/environment 162 | ;; 163 | *) 164 | OS_TYPE=0 165 | REPO_CONF= 166 | ETC_ENV= 167 | echo "***** ERROR: Can't detect OS Type (e.g., Ubuntu, Centos)! *****" 168 | echo "Abort now!" 169 | exit 9 170 | ;; 171 | esac 172 | } 173 | detectOS 174 | 175 | #### -------------------------------------------------------------------------------------------- 176 | ## -- CentOS 177 | # CERTITICATES_INSTALL_DIR=${CERTITICATES_INSTALL_DIR:-/etc/pki/ca-trust/source/anchors} 178 | ## -- Debian/Ubuntu 179 | # /etc/ca-certificates 180 | # /usr/local/share/ca-certificates 181 | # /usr/sbin/update-ca-certificates 182 | # /usr/share/doc/ca-certificates 183 | # /usr/share/ca-certificates 184 | # /var/lib/dpkg/triggers/update-ca-certificates 185 | # CERTITICATES_INSTALL_DIR=${CERTITICATES_INSTALL_DIR:-/usr/local/share/ca-certificates} 186 | # CERTITICATES_INSTALL_DIR=${CERTITICATES_INSTALL_DIR:-/usr/share/ca-certificates} 187 | # CERTITICATES_INSTALL_DIR=${CERTITICATES_INSTALL_DIR:-/etc/ca-certificates} 188 | # CERTITICATES_INSTALL_DIR=${CERTITICATES_INSTALL_DIR:-/etc/ssl/certs} 189 | 190 | ## -- Converting from PEM to CRT: -- ## 191 | ## openssl x509 -ouform der -in Some-Certificate.pem -out Some-Certificate.crt 192 | 193 | # update-ca-certificates # (for Ubuntu OS) 194 | # # update-ca-trust extract # (for CentOS OS) 195 | #### (Unbunt version) 196 | #CERTITICATES_INSTALL_DIR=/usr/local/share/ca-certificates/extra 197 | #### -------------------------------------------------------------------------------------------- 198 | 199 | #### ---- Targeted OS' Certificates Install Directory: ---- #### 200 | 201 | 202 | if [ $OS_TYPE -eq 1 ]; then 203 | # ------------ 204 | # -- Ubuntu -- 205 | # ------------ 206 | #CERT_COMMAND=`which update-ca-certificates` 207 | CERT_COMMAND=/usr/sbin/update-ca-certificates 208 | CMD_OPT= 209 | CERTITICATES_INSTALL_DIR=${CERTITICATES_INSTALL_DIR:-/usr/local/share/ca-certificates} 210 | elif [ $OS_TYPE -eq 2 ]; then 211 | # ------------ 212 | # -- CentOS -- 213 | # ------------ 214 | #CERT_COMMAND=`which update-ca-trust` 215 | CERT_COMMAND=/usr/bin/update-ca-trust 216 | #CMD_OPT=extract 217 | #CMD_OPT="force-enable" 218 | CMD_OPT= 219 | CERTITICATES_INSTALL_DIR=${CERTITICATES_INSTALL_DIR:-/etc/pki/ca-trust/source/anchors/} 220 | elif [ $OS_TYPE -eq 3 ]; then 221 | # ------------ 222 | # -- Alpine -- 223 | # ------------ 224 | # https://hackernoon.com/alpine-docker-image-with-secured-communication-ssl-tls-go-restful-api-128eb6b54f1f 225 | CERT_COMMAND=`which update-ca-certificates` 226 | #CERT_COMMAND=/usr/sbin/update-ca-certificates 227 | CMD_OPT= 228 | CERTITICATES_INSTALL_DIR=${CERTITICATES_INSTALL_DIR:-/usr/local/share/ca-certificates/} 229 | #CERTIFICATES_FILE=${CERTIFICATES_FILE:-mitre-chain.txt} 230 | # wget -O mitre-chain.crt --no-check-certificate https://gitlab.mitre.org/mitre-scripts/mitre-pki/raw/master/normalized/mitre-chain.txt 231 | #wget -O ${CERTIFICATES_FILE} --no-check-certificate https://gitlab.mitre.org/mitre-scripts/mitre-pki/raw/master/normalized/${CERTIFICATES_FILE} 232 | apk update && apk add ca-certificates && rm -rf /var/cache/apk/* 233 | #cp ${CERTIFICATES_FILE} /usr/local/share/ca-certificates/ 234 | #update-ca-certificates 235 | else 236 | echo -e ">>> ========================================" 237 | echo -e ">>> ERROR: OS_TYPE Unknown! Can't do! Abort!" 238 | echo -e ">>> ========================================" 239 | exit 1 240 | fi 241 | 242 | 243 | function setupSystemCertificates() { 244 | echo "================= Setup System Certificates ====================" 245 | if [ ! -s ${CERTITICATES_INSTALL_DIR} ]; then 246 | echo -e ">>> WARNING: CERTITICATES_INSTALL_DIR: ${CERTITICATES_INSTALL_DIR}: Not Found!" 247 | $sudo mkdir -p ${CERTITICATES_INSTALL_DIR} 248 | fi 249 | if [ -s /etc/ca-certificates/update.d/docker-openjdk ]; then 250 | sudo cat /etc/ca-certificates/update.d/docker-openjdk 251 | echo ">> JAVA PATH=`which java`" 252 | $sudo sed -i "s#\$JAVA_HOME#$JAVA_HOME#g" /etc/ca-certificates/update.d/docker-openjdk 253 | env | grep -i java 254 | sudo cat /etc/ca-certificates/update.d/docker-openjdk 255 | fi 256 | $sudo ls -al ${SOURCE_CERTIFICATES_DIR}/* 257 | echo -e ">>> ------------------------------" 258 | echo -e ">>> ------------------------------" 259 | echo -e ">>> /certificates: ${CERT_FILES}" 260 | echo -e ">>> ------------------------------" 261 | #for certificate in `$sudo ls ${SOURCE_CERTIFICATES_DIR}/* | grep '*.pem\|*.crt' | grep -v dummy`; do 262 | CERT_FILES=`find ${SOURCE_CERTIFICATES_DIR} -type f |grep -v dummy|grep 'crt\|pem'` 263 | for cert_file in ${CERT_FILES}; do 264 | echo -e ">>> Adding Certificate file: ${cert_file}" 265 | filename=$(basename -- "$cert_file") 266 | extension="${filename##*.}" 267 | ## -- Converting from PEM to CRT: -- ## 268 | ## openssl x509 -ouform der -in Some-Certificate.pem -out Some-Certificate.crt 269 | #if [[ "${cert_file}" == *"pem" ]]; then 270 | if [ "${extension}" == "pem" ]; then 271 | $sudo openssl x509 -ouform der -in ${cert_file} -out ${SOURCE_CERTIFICATES_DIR}/${filename//pem/crt} 272 | fi 273 | #if [[ "${cert_file}" == *"crt" ]]; then 274 | if [ "${extension}" == "crt" ]; then 275 | #$sudo cp root.cert.pem /usr/local/share/ca-certificates/root.cert.crt 276 | # $sudo cp ${SOURCE_CERTIFICATES_DIR}/${cert} ${CERTITICATES_INSTALL_DIR}/${filename} 277 | $sudo cp ${cert_file} ${CERTITICATES_INSTALL_DIR}/ 278 | else 279 | echo "... ignore non-certificate file: $cert" 280 | fi 281 | done 282 | $sudo ${CERT_COMMAND} ${CMD_OPT} 283 | } 284 | setupSystemCertificates 285 | 286 | #### -------------------------------------------------------------------------------------------- 287 | #### ---- Browsers (Firefox, Chromium, etc.) Root Certificates Setup 288 | #### ---- (ref: https://thomas-leister.de/en/how-to-import-ca-root-certificate/) 289 | #### -------------------------------------------------------------------------------------------- 290 | function setupBrowserRootCertificates() { 291 | ### Script installs root.cert.pem to certificate trust store of applications using NSS 292 | ### (e.g. Firefox, Thunderbird, Chromium) 293 | ### Mozilla uses cert8, Chromium and Chrome use cert9 294 | 295 | ### 296 | ### Requirement: apt install libnss3-tools 297 | ### 298 | 299 | 300 | ### 301 | ### CA file to install (CUSTOMIZE!) 302 | ### 303 | 304 | certfile="root.cert.pem" 305 | certname="My Root CA" 306 | 307 | ### 308 | ### For cert8 (legacy - DBM) 309 | ### 310 | 311 | for certDB in $(find ~/ -name "cert8.db") 312 | do 313 | certdir=$(dirname ${certDB}); 314 | certutil -A -n "${certname}" -t "TCu,Cu,Tu" -i ${certfile} -d dbm:${certdir} 315 | done 316 | 317 | ### 318 | ### For cert9 (SQL) 319 | ### 320 | 321 | for certDB in $(find ~/ -name "cert9.db") 322 | do 323 | certdir=$(dirname ${certDB}); 324 | certutil -A -n "${certname}" -t "TCu,Cu,Tu" -i ${certfile} -d sql:${certdir} 325 | done 326 | } 327 | 328 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set +e 4 | 5 | MY_DIR=$(dirname "$(readlink -f "$0")") 6 | 7 | if [ $# -lt 1 ]; then 8 | echo "--------------------------------------------------------" 9 | echo "Usage: " 10 | echo " ${0} " 11 | echo "e.g.: " 12 | echo " ${0} ls -al " 13 | echo " ${0} /bin/bash " 14 | echo "--------------------------------------------------------" 15 | fi 16 | 17 | ########################################################################### 18 | #### ---- RUN Configuration (CHANGE THESE if needed!!!!) --- #### 19 | ########################################################################### 20 | ## ------------------------------------------------------------------------ 21 | ## Valid "BUILD_TYPE" values: 22 | ## 0: (default) has neither X11 nor VNC/noVNC container build image type 23 | ## 1: X11/Desktip container build image type 24 | ## 2: VNC/noVNC container build image type 25 | ## ------------------------------------------------------------------------ 26 | BUILD_TYPE=1 27 | 28 | ## ------------------------------------------------------------------------ 29 | ## Valid "RUN_TYPE" values: 30 | ## 0: (default) Interactive Container - 31 | ## ==> Best for Debugging Use 32 | ## 1: Detach Container / Non-Interactive 33 | ## ==> Usually, when not in debugging mode anymore, then use 1 as choice. 34 | ## ==> Or, your frequent needs of the container for DEV environment Use. 35 | ## ------------------------------------------------------------------------ 36 | if [ "$1" = "-d" ]; then 37 | RUN_TYPE=1 38 | shift 1 39 | fi 40 | RUN_TYPE=${RUN_TYPE:-0} 41 | 42 | ## ------------------------------------------------------------------------ 43 | ## -- Container 'hostname' use: 44 | ## -- Default= 1 (use HOST_IP) 45 | ## -- 1: HOST_IP 46 | ## -- 2: HOST_NAME 47 | ## ------------------------------------------------------------------------ 48 | HOST_USE_IP_OR_NAME=${HOST_USE_IP_OR_NAME:-1} 49 | 50 | ######################################## 51 | #### ---- NVIDIA GPU Checking: ---- #### 52 | ######################################## 53 | ## ------------------------------------------------------------------------ 54 | ## Run with GPU or not 55 | ## 0: (default) Not using host's USER / GROUP ID 56 | ## 1: Yes, using host's USER / GROUP ID for Container running. 57 | ## ------------------------------------------------------------------------ 58 | 59 | NVIDIA_DOCKER_AVAILABLE=0 60 | function check_NVIDIA() { 61 | NVIDIA_PCI=`lspci | grep VGA | grep -i NVIDIA` 62 | if [ "$NVIDIA_PCI" == "" ]; then 63 | echo "---- No Nvidia PCI found! No Nvidia/GPU physical card(s) available! Use CPU only!" 64 | GPU_OPTION= 65 | else 66 | which nvidia-smi 67 | if [ $? -ne 0 ]; then 68 | echo "---- No nvidia-smi command! No Nvidia/GPU driver setup! Use CPU only!" 69 | GPU_OPTION= 70 | else 71 | NVIDIA_SMI=`nvidia-smi | grep -i NVIDIA | grep -i CUDA` 72 | if [ "$NVIDIA_SMI" == "" ]; then 73 | echo "---- No nvidia-smi command not function correctly. Use CPU only!" 74 | GPU_OPTION= 75 | else 76 | echo ">>>> Found Nvidia GPU: Use all GPU(s)!" 77 | echo "${NVIDIA_SMI}" 78 | GPU_OPTION=" --gpus all " 79 | fi 80 | if [ ${IS_TO_RUN_CPU} -gt 0 ]; then 81 | GPU_OPTION= 82 | fi 83 | fi 84 | fi 85 | } 86 | #check_NVIDIA 87 | #echo "GPU_OPTION= ${GPU_OPTION}" 88 | 89 | #echo "$@" 90 | 91 | ## ------------------------------------------------------------------------ 92 | ## Change to one (1) if run.sh needs to use host's user/group to run the Container 93 | ## Valid "USER_VARS_NEEDED" values: 94 | ## 0: (default) Not using host's USER / GROUP ID 95 | ## 1: Yes, using host's USER / GROUP ID for Container running. 96 | ## ------------------------------------------------------------------------ 97 | USER_VARS_NEEDED=0 98 | 99 | ## ------------------------------------------------------------------------ 100 | ## Valid "RESTART_OPTION" values: 101 | ## { no, on-failure, unless-stopped, always } 102 | ## ------------------------------------------------------------------------ 103 | if [ "$1" = "-a" ] && [ "${RUN_TYPE}" = "1" ] ; then 104 | RESTART_OPTION=always 105 | shift 1 106 | fi 107 | RESTART_OPTION=${RESTART_OPTION:-no} 108 | 109 | ## ------------------------------------------------------------------------ 110 | ## More optional values: 111 | ## Add any additional options here 112 | ## ------------------------------------------------------------------------ 113 | #MORE_OPTIONS="--privileged=true" 114 | MORE_OPTIONS="" 115 | 116 | ## ------------------------------------------------------------------------ 117 | ## Multi-media optional values: 118 | ## Add any additional options here 119 | ## ------------------------------------------------------------------------ 120 | #MEDIA_OPTIONS=" --device /dev/snd --device /dev/dri --device /dev/video0 --group-add audio --group-add video " 121 | #MEDIA_OPTIONS=" --group-add audio --group-add video --device /dev/snd --device /dev/dri " 122 | MEDIA_OPTIONS= 123 | 124 | ############################################################################### 125 | ############################################################################### 126 | ############################################################################### 127 | #### ---- DO NOT Change the code below UNLESS you really want to !!!!) --- #### 128 | #### ---- DO NOT Change the code below UNLESS you really want to !!!!) --- #### 129 | #### ---- DO NOT Change the code below UNLESS you really want to !!!!) --- #### 130 | ############################################################################### 131 | ############################################################################### 132 | ############################################################################### 133 | 134 | ######################################## 135 | #### ---- Correctness Checking ---- #### 136 | ######################################## 137 | RESTART_OPTION=`echo ${RESTART_OPTION} | sed 's/ //g' | tr '[:upper:]' '[:lower:]' ` 138 | REMOVE_OPTION=" --rm " 139 | if [ "${RESTART_OPTION}" != "no" ]; then 140 | REMOVE_OPTION="" 141 | fi 142 | 143 | ######################################## 144 | #### ---- Usage for BUILD_TYPE ---- #### 145 | ######################################## 146 | function buildTypeUsage() { 147 | echo "## ------------------------------------------------------------------------" 148 | echo "## Valid BUILD_TYPE values: " 149 | echo "## 0: (default) has neither X11 nor VNC/noVNC container build image type" 150 | echo "## 1: X11/Desktip container build image type" 151 | echo "## 2: VNC/noVNC container build image type" 152 | echo "## ------------------------------------------------------------------------" 153 | } 154 | 155 | if [ "${BUILD_TYPE}" -lt 0 ] || [ "${BUILD_TYPE}" -gt 2 ]; then 156 | buildTypeUsage 157 | exit 1 158 | fi 159 | 160 | ######################################## 161 | #### ---- Validate RUN_TYPE ---- #### 162 | ######################################## 163 | 164 | RUN_OPTION=${RUN_OPTION:-" -it "} 165 | function validateRunType() { 166 | case "${RUN_TYPE}" in 167 | 0 ) 168 | RUN_OPTION=" -it " 169 | ;; 170 | 1 ) 171 | RUN_OPTION=" -d " 172 | ;; 173 | * ) 174 | echo "**** ERROR: Incorrect RUN_TYPE: ${RUN_TYPE} is used! Abort ****" 175 | exit 1 176 | ;; 177 | esac 178 | } 179 | validateRunType 180 | echo "RUN_TYPE=${RUN_TYPE}" 181 | echo "RUN_OPTION=${RUN_OPTION}" 182 | echo "RESTART_OPTION=${RESTART_OPTION}" 183 | echo "REMOVE_OPTION=${REMOVE_OPTION}" 184 | 185 | ########################################################################### 186 | ## -- docker-compose or docker-stack use only -- 187 | ########################################################################### 188 | 189 | ## -- (this script will include ./.env only if "./docker-run.env" not found 190 | DOCKER_ENV_FILE="./docker-run.env" 191 | 192 | ########################################################################### 193 | #### (Optional - to filter Environmental Variables for Running Docker) 194 | ########################################################################### 195 | ENV_VARIABLE_PATTERN="" 196 | 197 | ################################################### 198 | #### ---- Change this only to use your own ---- 199 | ################################################### 200 | ORGANIZATION=openkbs 201 | baseDataFolder="$HOME/data-docker" 202 | 203 | ################################################### 204 | #### ---- Detect Host OS Type and minor Tweek: ---- 205 | ################################################### 206 | ################################################### 207 | #### **** Container HOST information **** 208 | ################################################### 209 | SED_MAC_FIX="''" 210 | CP_OPTION="--backup=numbered" 211 | HOST_IP=127.0.0.1 212 | HOST_NAME=localhost 213 | function get_HOST_IP() { 214 | if [[ "$OSTYPE" == "linux-gnu" ]]; then 215 | # Linux ... 216 | HOST_NAME=`hostname -f` 217 | HOST_IP=`ip route get 1|grep via | awk '{print $7}'` 218 | SED_MAC_FIX= 219 | elif [[ "$OSTYPE" == "darwin"* ]]; then 220 | # Mac OSX 221 | HOST_NAME=`hostname -f` 222 | HOST_IP=`ifconfig | grep "inet " | grep -Fv 127.0.0.1 | grep -Fv 192.168 | awk '{print $2}'` 223 | CP_OPTION= 224 | else 225 | HOST_NAME=`hostname -f` 226 | echo "**** Unknown/unsupported HOST OS type: $OSTYPE" 227 | echo ">>>> Use defaults: HOST_IP=$HOST_IP ; HOST_NAME=$HOST_NAME" 228 | fi 229 | echo ">>> HOST_IP=${HOST_IP}" 230 | echo ">>> HOST_NAME=${HOST_NAME}" 231 | } 232 | get_HOST_IP 233 | HOST_IP=${HOST_IP:-127.0.0.1} 234 | HOST_NAME=${HOST_NAME:-localhost} 235 | 236 | ################################################### 237 | #### **** Container package information **** 238 | ################################################### 239 | DOCKER_IMAGE_REPO=`echo $(basename $PWD)|tr '[:upper:]' '[:lower:]'|tr "/: " "_" ` 240 | imageTag="${ORGANIZATION}/${DOCKER_IMAGE_REPO}" 241 | #PACKAGE=`echo ${imageTag##*/}|tr "/\-: " "_"` 242 | PACKAGE="${imageTag##*/}" 243 | 244 | ################################################### 245 | #### ---- (DEPRECATED but still supported) ----- 246 | #### ---- Volumes to be mapped (change this!) ----- 247 | ################################################### 248 | # (examples) 249 | # IDEA_PRODUCT_NAME="IdeaIC2017" 250 | # IDEA_PRODUCT_VERSION="3" 251 | # IDEA_INSTALL_DIR="${IDEA_PRODUCT_NAME}.${IDEA_PRODUCT_VERSION}" 252 | # IDEA_CONFIG_DIR=".${IDEA_PRODUCT_NAME}.${IDEA_PRODUCT_VERSION}" 253 | # IDEA_PROJECT_DIR="IdeaProjects" 254 | # VOLUMES_LIST="${IDEA_CONFIG_DIR} ${IDEA_PROJECT_DIR}" 255 | 256 | # --------------------------- 257 | # Variable: VOLUMES_LIST 258 | # (NEW: use docker.env with "#VOLUMES_LIST=data workspace" to define entries) 259 | # --------------------------- 260 | ## -- If you defined locally here, 261 | ## then the definitions of volumes map in "docker.env" will be ignored. 262 | # VOLUMES_LIST="data workspace" 263 | 264 | # --------------------------- 265 | # OPTIONAL Variable: PORT PAIR 266 | # (NEW: use docker.env with "#PORTS=18000:8000 17200:7200" to define entries) 267 | # --------------------------- 268 | ## -- If you defined locally here, 269 | ## then the definitions of ports map in "docker.env" will be ignored. 270 | #### Input: PORT - list of PORT to be mapped 271 | # (examples) 272 | #PORTS_LIST="18000:8000" 273 | #PORTS_LIST= 274 | 275 | ######################################################################################################### 276 | ######################## DON'T CHANGE LINES STARTING BELOW (unless you need to) ######################### 277 | ######################################################################################################### 278 | LOCAL_VOLUME_DIR="${baseDataFolder}/${PACKAGE}" 279 | ## -- Container's internal Volume base DIR 280 | DOCKER_VOLUME_DIR="/home/developer" 281 | 282 | ################################################### 283 | #### ---- Detect Docker Run Env files ---- 284 | ################################################### 285 | 286 | function detectDockerRunEnvFile() { 287 | curr_dir=`pwd` 288 | if [ -s "${DOCKER_ENV_FILE}" ]; then 289 | echo "--- INFO: Docker Run Environment file '${DOCKER_ENV_FILE}' FOUND!" 290 | else 291 | echo "*** WARNING: Docker Run Environment file '${DOCKER_ENV_FILE}' NOT found!" 292 | echo "*** WARNING: Searching for .env or docker.env as alternative!" 293 | echo "*** --->" 294 | if [ -s "./docker-run.env" ]; then 295 | echo "--- INFO: ./docker-run.env FOUND to use as Docker Run Environment file!" 296 | DOCKER_ENV_FILE="./docker-run.env" 297 | else 298 | if [ -s "./.env" ]; then 299 | echo "--- INFO: ./.env FOUND to use as Docker Run Environment file!" 300 | DOCKER_ENV_FILE="./.env" 301 | else 302 | echo "--- INFO: ./.env Docker Environment file (.env) NOT found!" 303 | if [ -s "./docker.env" ]; then 304 | echo "--- INFO: ./docker.env FOUND to use as Docker Run Environment file!" 305 | DOCKER_ENV_FILE="./docker.env" 306 | else 307 | echo "*** WARNING: Docker Environment file (.env) or (docker.env) NOT found!" 308 | fi 309 | fi 310 | fi 311 | fi 312 | } 313 | detectDockerRunEnvFile 314 | 315 | ################################################### 316 | #### ---- Function: Generate volume mappings ---- 317 | #### (Don't change!) 318 | ################################################### 319 | VOLUME_MAP="" 320 | #### Input: VOLUMES - list of volumes to be mapped 321 | hasPattern=0 322 | function hasPattern() { 323 | detect=`echo $1|grep "$2"` 324 | if [ "${detect}" != "" ]; then 325 | hasPattern=1 326 | else 327 | hasPattern=0 328 | fi 329 | } 330 | 331 | DEBUG=0 332 | function debug() { 333 | if [ $DEBUG -gt 0 ]; then 334 | echo $* 335 | fi 336 | } 337 | 338 | function cutomizedVolume() { 339 | DATA_VOLUME=$1 340 | if [ "`echo $DATA_VOLUME|grep 'volume-'`" != "" ]; then 341 | docker_volume=`echo $DATA_VOLUME | cut -d'-' -f2 | cut -d':' -f1` 342 | dest_volume=`echo $DATA_VOLUME | cut -d'-' -f2 | cut -d':' -f2` 343 | source_volume=$(basename $imageTag)_${docker_volume} 344 | sudo docker volume create ${source_volume} 345 | 346 | VOLUME_MAP="-v ${source_volume}:${dest_volume} ${VOLUME_MAP}" 347 | else 348 | echo "---- ${DATA_VOLUME} already is defined! Hence, ignore setup ${DATA_VOLUME} ..." 349 | echo "---> VOLUME_MAP=${VOLUME_MAP}" 350 | fi 351 | } 352 | 353 | function checkHostVolumePath() { 354 | _left=$1 355 | mkdir -p ${_left} 356 | sudo chown -R $USER:$USER ${_left} 357 | if [ -s ${_left} ]; then 358 | ls -al ${_left} 359 | else 360 | echo "*** ERROR: ${_left}: Not existing!" 361 | fi 362 | } 363 | 364 | function generateVolumeMapping() { 365 | if [ "$VOLUMES_LIST" == "" ]; then 366 | ## -- If locally defined in this file, then respect that first. 367 | ## -- Otherwise, go lookup the docker.env as ride-along source for volume definitions 368 | VOLUMES_LIST=`cat ${DOCKER_ENV_FILE}|grep "^#VOLUMES_LIST= *"|sed "s/[#\"]//g"|cut -d'=' -f2-` 369 | fi 370 | for vol in $VOLUMES_LIST; do 371 | echo 372 | echo ">>>>>>>>> $vol" 373 | hasColon=`echo $vol|grep ":"` 374 | ## -- allowing change local volume directories -- 375 | if [ "$hasColon" != "" ]; then 376 | if [ "`echo $vol|grep 'volume-'`" != "" ]; then 377 | cutomizedVolume $vol 378 | else 379 | echo "************* hasColon=$hasColon" 380 | left=`echo $vol|cut -d':' -f1` 381 | right=`echo $vol|cut -d':' -f2` 382 | leftHasDot=`echo $left|grep "^\./"` 383 | if [ "$leftHasDot" != "" ]; then 384 | ## has "./data" on the left 385 | debug "******** A. Left HAS Dot pattern: leftHasDot=$leftHasDot" 386 | if [[ ${right} == "/"* ]]; then 387 | ## -- pattern like: "./data:/containerPath/data" 388 | echo "******* A-1 -- pattern like ./data:/data --" 389 | VOLUME_MAP="${VOLUME_MAP} -v `pwd`/${left#./}:${right}" 390 | else 391 | ## -- pattern like: "./data:data" 392 | echo "******* A-2 -- pattern like ./data:data --" 393 | VOLUME_MAP="${VOLUME_MAP} -v `pwd`/${left#./}:${DOCKER_VOLUME_DIR}/${right}" 394 | fi 395 | checkHostVolumePath "`pwd`/${left}" 396 | else 397 | ## No "./data" on the left 398 | debug "******** B. Left No ./data on the left: leftHasDot=$leftHasDot" 399 | leftHasAbsPath=`echo $left|grep "^/.*"` 400 | if [ "$leftHasAbsPath" != "" ]; then 401 | debug "******* B-1 ## Has pattern like /data on the left " 402 | if [[ ${right} == "/"* ]]; then 403 | ## -- pattern like: "/data:/containerPath/data" 404 | echo "****** B-1-a pattern like /data:/containerPath/data --" 405 | VOLUME_MAP="${VOLUME_MAP} -v ${left}:${right}" 406 | else 407 | ## -- pattern like: "/data:data" 408 | echo "----- B-1-b pattern like /data:data --" 409 | VOLUME_MAP="${VOLUME_MAP} -v ${left}:${DOCKER_VOLUME_DIR}/${right}" 410 | fi 411 | checkHostVolumePath "${left}" 412 | else 413 | debug "******* B-2 ## No pattern like /data on the left" 414 | rightHasAbsPath=`echo $right|grep "^/.*"` 415 | debug ">>>>>>>>>>>>> rightHasAbsPath=$rightHasAbsPath" 416 | if [[ ${right} == "/"* ]]; then 417 | echo "****** B-2-a pattern like: data:/containerPath/data" 418 | debug "-- pattern like ./data:/data --" 419 | VOLUME_MAP="${VOLUME_MAP} -v ${LOCAL_VOLUME_DIR}/${left}:${right}" 420 | else 421 | debug "****** B-2-b ## -- pattern like: data:data" 422 | VOLUME_MAP="${VOLUME_MAP} -v ${LOCAL_VOLUME_DIR}/${left}:${DOCKER_VOLUME_DIR}/${right}" 423 | fi 424 | checkHostVolumePath "${left}" 425 | fi 426 | fi 427 | fi 428 | else 429 | ## -- pattern like: "data" 430 | debug "-- default sub-directory (without prefix absolute path) --" 431 | VOLUME_MAP="${VOLUME_MAP} -v ${LOCAL_VOLUME_DIR}/$vol:${DOCKER_VOLUME_DIR}/$vol" 432 | mkdir -p ${LOCAL_VOLUME_DIR}/$vol 433 | if [ $DEBUG -gt 0 ]; then ls -al ${LOCAL_VOLUME_DIR}/$vol; fi 434 | fi 435 | echo ">>> expanded VOLUME_MAP: ${VOLUME_MAP}" 436 | done 437 | } 438 | #### ---- Generate Volumes Mapping ---- 439 | generateVolumeMapping 440 | echo ${VOLUME_MAP} 441 | 442 | ################################################### 443 | #### ---- Function: Generate port mappings ---- 444 | #### (Don't change!) 445 | ################################################### 446 | PORT_MAP="" 447 | function generatePortMapping() { 448 | if [ "$PORTS" == "" ]; then 449 | ## -- If locally defined in this file, then respect that first. 450 | ## -- Otherwise, go lookup the ${DOCKER_ENV_FILE} as ride-along source for volume definitions 451 | PORTS_LIST=`cat ${DOCKER_ENV_FILE}|grep "^#PORTS_LIST= *"|sed "s/[#\"]//g"|cut -d'=' -f2-` 452 | fi 453 | for pp in ${PORTS_LIST}; do 454 | #echo "$pp" 455 | port_pair=`echo $pp | tr -d ' ' ` 456 | if [ ! "$port_pair" == "" ]; then 457 | # -p ${local_dockerPort1}:${dockerPort1} 458 | host_port=`echo $port_pair | tr -d ' ' | cut -d':' -f1` 459 | docker_port=`echo $port_pair | tr -d ' ' | cut -d':' -f2` 460 | PORT_MAP="${PORT_MAP} -p ${host_port}:${docker_port}" 461 | fi 462 | done 463 | } 464 | #### ---- Generate Port Mapping ---- 465 | generatePortMapping 466 | echo "PORT_MAP=${PORT_MAP}" 467 | 468 | ################################################### 469 | #### ---- Generate Environment Variables ---- 470 | ################################################### 471 | ENV_VARS="" 472 | function generateEnvVars_v2() { 473 | while read line; do 474 | echo "Line=$line" 475 | key=${line%=*} 476 | value=${line#*=} 477 | key=$(eval echo $value) 478 | ENV_VARS="${ENV_VARS} -e ${line%=*}=$(eval echo $value)" 479 | done < <(grep -E "^[[:blank:]]*$1.+[[:blank:]]*=[[:blank:]]*.+[[:blank:]]*" ${DOCKER_ENV_FILE} | grep -v "^#") 480 | echo "ENV_VARS=$ENV_VARS" 481 | } 482 | generateEnvVars_v2 483 | echo ">> ENV_VARS=$ENV_VARS" 484 | 485 | function generateEnvVars() { 486 | if [ "${1}" != "" ]; then 487 | ## -- product key patterns, e.g., "^MYSQL_*" 488 | #productEnvVars=`grep -E "^[[:blank:]]*$1[a-zA-Z0-9_]+[[:blank:]]*=[[:blank:]]*[a-zA-Z0-9_]+[[:blank:]]*" ${DOCKER_ENV_FILE}` 489 | productEnvVars=`grep -E "^[[:blank:]]*$1.+[[:blank:]]*=[[:blank:]]*.+[[:blank:]]*" ${DOCKER_ENV_FILE} | grep -v "^#" | grep "${1}"` 490 | else 491 | ## -- product key patterns, e.g., "^MYSQL_*" 492 | #productEnvVars=`grep -E "^[[:blank:]]*$1[a-zA-Z0-9_]+[[:blank:]]*=[[:blank:]]*[a-zA-Z0-9_]+[[:blank:]]*" ${DOCKER_ENV_FILE}` 493 | productEnvVars=`grep -E "^[[:blank:]]*$1.+[[:blank:]]*=[[:blank:]]*.+[[:blank:]]*" ${DOCKER_ENV_FILE} | grep -v "^#"` 494 | fi 495 | for vars in 496 | do 497 | echo "Line=$line" 498 | key=${line%=*} 499 | value=${line#*=} 500 | #key=$(eval echo $value) 501 | #ENV_VARS="${ENV_VARS} -e ${line%=*}=$(eval echo $value)" 502 | ENV_VARS="${ENV_VARS} -e ${line}" 503 | done 504 | ENV_VARS_STRING="" 505 | for vars in ${productEnvVars// /}; do 506 | debug "Entry => $vars" 507 | key=${vars%=*} 508 | value=${vars#*=} 509 | if [ "$1" != "" ]; then 510 | matched=`echo $vars|grep -E "${1}"` 511 | if [ ! "$matched" == "" ]; then 512 | ENV_VARS="${ENV_VARS} -e $key=$(eval echo $value)" 513 | #ENV_VARS="${ENV_VARS} ${vars}" 514 | fi 515 | else 516 | #ENV_VARS="${ENV_VARS} ${vars}" 517 | ENV_VARS="${ENV_VARS} -e $key=$(eval echo $value)" 518 | fi 519 | done 520 | # ## IFS default is "space tab newline" already 521 | # #IFS=',; ' read -r -a ENV_VARS_ARRAY <<< "${ENV_VARS_STRING}" 522 | # read -r -a ENV_VARS_ARRAY <<< "${ENV_VARS_STRING}" 523 | # # To iterate over the elements: 524 | # for element in "${ENV_VARS_ARRAY[@]}" 525 | # do 526 | # ENV_VARS="${ENV_VARS} -e ${element}" 527 | # done 528 | # if [ $DEBUG -gt 0 ]; then echo "ENV_VARS_ARRAY=${ENV_VARS_ARRAY[@]}"; fi 529 | } 530 | #generateEnvVars 531 | #echo "ENV_VARS=${ENV_VARS}" 532 | 533 | ################################################### 534 | #### ---- Setup Docker Build Proxy ---- 535 | ################################################### 536 | # export NO_PROXY="localhost,127.0.0.1,.openkbs.org" 537 | # export HTTP_PROXY="http://gatekeeper-w.openkbs.org:80" 538 | # when using "wget", add "--no-check-certificate" to avoid https certificate checking failures 539 | # Note: You can also setup Docker CLI configuration file (~/.docker/config.json), e.g. 540 | # { 541 | # "proxies": { 542 | # "default": { 543 | # "httpProxy": "http://gatekeeper-w.openkbs.org:80" 544 | # "httpsProxy": "http://gatekeeper-w.openkbs.org:80" 545 | # } 546 | # } 547 | # } 548 | # 549 | echo "... Setup Docker Run Proxy: ..." 550 | 551 | PROXY_PARAM= 552 | function generateProxyEnv() { 553 | if [ "${HTTP_PROXY}" != "" ]; then 554 | PROXY_PARAM="${PROXY_PARAM} -e HTTP_PROXY=${HTTP_PROXY}" 555 | fi 556 | if [ "${HTTPS_PROXY}" != "" ]; then 557 | PROXY_PARAM="${PROXY_PARAM} -e HTTPS_PROXY=${HTTPS_PROXY}" 558 | fi 559 | if [ "${NO_PROXY}" != "" ]; then 560 | PROXY_PARAM="${PROXY_PARAM} -e NO_PROXY=\"${NO_PROXY}\"" 561 | fi 562 | if [ "${http_proxy}" != "" ]; then 563 | PROXY_PARAM="${PROXY_PARAM} -e http_proxy=${http_proxy}" 564 | fi 565 | if [ "${https_proxy}" != "" ]; then 566 | PROXY_PARAM="${PROXY_PARAM} -e https_proxy=${https_proxy}" 567 | fi 568 | if [ "${no_proxy}" != "" ]; then 569 | PROXY_PARAM="${PROXY_PARAM} -e no_proxy=\"${no_proxy}\"" 570 | fi 571 | ENV_VARS="${ENV_VARS} ${PROXY_PARAM}" 572 | } 573 | generateProxyEnv 574 | echo "ENV_VARS=${ENV_VARS}" 575 | 576 | ################################################### 577 | #### ---- Function: Generate privilege String ---- 578 | #### (Don't change!) 579 | ################################################### 580 | privilegedString="" 581 | function generatePrivilegedString() { 582 | OS_VER=`which yum` 583 | if [ "$OS_VER" == "" ]; then 584 | # Ubuntu 585 | echo "Ubuntu ... not SE-Lunix ... no privileged needed" 586 | else 587 | # CentOS/RHEL 588 | privilegedString="--privileged" 589 | fi 590 | } 591 | generatePrivilegedString 592 | echo ${privilegedString} 593 | 594 | ################################################### 595 | #### ---- Mostly, you don't need change below ---- 596 | ################################################### 597 | function cleanup() { 598 | containerID=`sudo docker ps -a|grep "${instanceName}" | awk '{print $1}'` 599 | # if [ ! "`sudo docker ps -a|grep ${instanceName}`" == "" ]; then 600 | if [ "${containerID}" != "" ]; then 601 | sudo docker rm -f ${containerID} 602 | fi 603 | } 604 | 605 | ################################################### 606 | #### ---- Display Host (Container) URL with Port ---- 607 | ################################################### 608 | function displayURL() { 609 | port=${1} 610 | echo "... Go to: http://${MY_IP}:${port}" 611 | #firefox http://${MY_IP}:${port} & 612 | if [ "`which google-chrome`" != "" ]; then 613 | /usr/bin/google-chrome http://${MY_IP}:${port} & 614 | else 615 | firefox http://${MY_IP}:${port} & 616 | fi 617 | } 618 | 619 | ################################################### 620 | #### ---- Replace "Key=Value" with new value ---- 621 | ################################################### 622 | function replaceKeyValue() { 623 | inFile=${1:-${DOCKER_ENV_FILE}} 624 | keyLike=$2 625 | newValue=$3 626 | if [ "$2" == "" ]; then 627 | echo "**** ERROR: Empty Key value! Abort!" 628 | exit 1 629 | fi 630 | sed -i -E 's/^('$keyLike'[[:blank:]]*=[[:blank:]]*).*/\1'$newValue'/' $inFile 631 | } 632 | #### ---- Replace docker.env with local user's UID and GID ---- 633 | #replaceKeyValue ${DOCKER_ENV_FILE} "USER_ID" "$(id -u $USER)" 634 | #replaceKeyValue ${DOCKER_ENV_FILE} "GROUP_ID" "$(id -g $USER)" 635 | 636 | ################################################### 637 | #### ---- Get "Key=Value" withe new value ---- 638 | #### Usage: getKeyValuePair 639 | #### Output: Key=Value 640 | ################################################### 641 | KeyValuePair="" 642 | function getKeyValuePair() { 643 | KeyValuePair="" 644 | inFile=${1:-${DOCKER_ENV_FILE}} 645 | keyLike=$2 646 | if [ "$2" == "" ]; then 647 | echo "**** ERROR: Empty Key value! Abort!" 648 | exit 1 649 | fi 650 | matchedKV=`grep -E "^[[:blank:]]*${keyLike}.+[[:blank:]]*=[[:blank:]]*.+[[:blank:]]*" ${DOCKER_ENV_FILE}` 651 | for kv in $matchedKV; do 652 | echo "KeyValuePair=${matchedKV// /}" 653 | done 654 | } 655 | #getKeyValuePair "${DOCKER_ENV_FILE}" "MYSQL_DATABASE" 656 | 657 | ## -- transform '-' and space to '_' 658 | #instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/\-: " "_"` 659 | instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/: " "_"` 660 | 661 | ################################################ 662 | ##### ---- Product Specific Parameters ---- #### 663 | ################################################ 664 | #MYSQL_DATABASE=${MYSQL_DATABASE:-myDB} 665 | #MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-password} 666 | #MYSQL_USER=${MYSQL_USER:-user1} 667 | #MYSQL_PASSWORD=${MYSQL_PASSWORD:-password} 668 | #### ---- Generate Env. Variables ---- 669 | echo ${ENV_VARS} 670 | 671 | echo "---------------------------------------------" 672 | echo "---- Starting a Container for ${imageTag}" 673 | echo "---------------------------------------------" 674 | 675 | cleanup 676 | 677 | ################################# 678 | ## -- USER_VARS into Docker -- ## 679 | ################################# 680 | if [ ${USER_VARS_NEEDED} -gt 0 ]; then 681 | USER_VARS="--user $(id -u $USER)" 682 | fi 683 | 684 | echo "--------------------------------------------------------" 685 | echo "==> Commands to manage Container:" 686 | echo "--------------------------------------------------------" 687 | echo " ./shell.sh : to shell into the container" 688 | echo " ./stop.sh : to stop the container" 689 | echo " ./log.sh : to show the docker run log" 690 | echo " ./build.sh : to build the container" 691 | echo " ./commit.sh: to push the container image to docker hub" 692 | echo "--------------------------------------------------------" 693 | 694 | ################################# 695 | ## ---- Detect Media/Sound: -- ## 696 | ################################# 697 | MEDIA_OPTIONS="" 698 | function detectMedia() { 699 | devices="/dev/snd /dev/dri" 700 | for device in $devices; do 701 | if [ -s $device ]; then 702 | # --device /dev/snd:/dev/snd 703 | if [ "${MEDIA_OPTIONS}" == "" ]; then 704 | MEDIA_OPTIONS=" --group-add audio --group-add video " 705 | fi 706 | # MEDIA_OPTIONS=" --group-add audio --group-add video --device /dev/snd --device /dev/dri " 707 | MEDIA_OPTIONS="${MEDIA_OPTIONS} --device $device:$device" 708 | fi 709 | done 710 | echo "MEDIA_OPTIONS= ${MEDIA_OPTION}" 711 | } 712 | detectMedia 713 | 714 | ################################# 715 | ## -_-- Setup X11 Display -_-- ## 716 | ################################# 717 | X11_OPTION= 718 | function setupDisplayType() { 719 | if [[ "$OSTYPE" == "linux-gnu" ]]; then 720 | # ... 721 | xhost +SI:localuser:$(id -un) 722 | xhost + 127.0.0.1 723 | echo ${DISPLAY} 724 | elif [[ "$OSTYPE" == "darwin"* ]]; then 725 | # Mac OSX 726 | # if you want to multi-media in MacOS, you need customize it here 727 |        MEDIA_OPTIONS="" 728 | xhost + 127.0.0.1 729 | export DISPLAY=host.docker.internal:0 730 | echo ${DISPLAY} 731 | elif [[ "$OSTYPE" == "cygwin" ]]; then 732 | # POSIX compatibility layer and Linux environment emulation for Windows 733 | xhost + 127.0.0.1 734 | echo ${DISPLAY} 735 | elif [[ "$OSTYPE" == "msys" ]]; then 736 | # Lightweight shell and GNU utilities compiled for Windows (part of MinGW) 737 | xhost + 127.0.0.1 738 | echo ${DISPLAY} 739 | elif [[ "$OSTYPE" == "freebsd"* ]]; then 740 | # ... 741 | xhost + 127.0.0.1 742 | echo ${DISPLAY} 743 | else 744 | # Unknown. 745 | echo "Unknown OS TYPE: $OSTYPE! Not supported!" 746 | exit 9 747 | fi 748 | echo "DISPLAY=${DISPLAY}" 749 | echo 750 | } 751 | 752 | 753 | ################################################## 754 | ## ---- Setup Corporate Chain's Certificates -- ## 755 | ################################################## 756 | CERTIFICATE_OPTIONS= 757 | function setupCorporateCertificates() { 758 | cert_dir=`pwd`/certificates 759 | if [ -d ./certificates/ ]; then 760 | CERTIFICATE_OPTIONS="${CERTIFICATE_OPTIONS} -v ${cert_dir}:/certificates" 761 | fi 762 | echo "CERTIFICATE_OPTIONS=${CERTIFICATE_OPTIONS}" 763 | } 764 | setupCorporateCertificates 765 | 766 | 767 | ################################################## 768 | ## ---- Setup accessing HOST's /etc/hosts: ---- ## 769 | ################################################## 770 | ## **************** WARNING: ********************* 771 | ## **************** WARNING: ********************* 772 | ## **************** WARNING: ********************* 773 | # => this might open up more attack surface since 774 | # /etc/hosts has other nodes IP/name information 775 | # ------------------------------------------------ 776 | if [ ${HOST_USE_IP_OR_NAME} -eq 2 ]; then 777 | HOSTS_OPTIONS="-h ${HOST_NAME} -v /etc/hosts:/etc/hosts " 778 | else 779 | # default use HOST_IP 780 | HOSTS_OPTIONS="-h ${HOST_IP} -v /etc/hosts:/etc/hosts " 781 | fi 782 | 783 | ################################################## 784 | ################################################## 785 | ## ----------------- main --------------------- ## 786 | ################################################## 787 | ################################################## 788 | set -x 789 | 790 | case "${BUILD_TYPE}" in 791 | 0) 792 | #### 0: (default) has neither X11 nor VNC/noVNC container build image type 793 | #### ---- for headless-based / GUI-less ---- #### 794 | MORE_OPTIONS="${MORE_OPTIONS} ${HOSTS_OPTIONS} " 795 | sudo docker run \ 796 | --name=${instanceName} \ 797 | --restart=${RESTART_OPTION} \ 798 | ${REMOVE_OPTION} ${RUN_OPTION} ${MORE_OPTIONS} ${CERTIFICATE_OPTIONS} \ 799 | ${privilegedString} \ 800 | ${USER_VARS} \ 801 | ${ENV_VARS} \ 802 | ${VOLUME_MAP} \ 803 | ${PORT_MAP} \ 804 | ${imageTag} \ 805 | $@ 806 | ;; 807 | 1) 808 | #### 1: X11/Desktip container build image type 809 | #### ---- for X11-based ---- #### 810 | setupDisplayType 811 | echo ${DISPLAY} 812 | #X11_OPTION="-e DISPLAY=$DISPLAY -v $HOME/.chrome:/data -v /dev/shm:/dev/shm -v /tmp/.X11-unix:/tmp/.X11-unix -e DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket" 813 | #X11_OPTION="-e DISPLAY=$DISPLAY -v /dev/shm:/dev/shm -v /tmp/.X11-unix:/tmp/.X11-unix -e DBUS_SYSTEM_BUS_ADDRESS=unix:path=/var/run/dbus/system_bus_socket" 814 | X11_OPTION="-e DISPLAY=$DISPLAY -v /dev/shm:/dev/shm -v /tmp/.X11-unix:/tmp/.X11-unix" 815 | echo "X11_OPTION=${X11_OPTION}" 816 | MORE_OPTIONS="${MORE_OPTIONS} ${HOSTS_OPTIONS} " 817 | sudo docker run \ 818 | --name=${instanceName} \ 819 | --restart=${RESTART_OPTION} \ 820 | ${MEDIA_OPTIONS} \ 821 | ${REMOVE_OPTION} ${RUN_OPTION} ${MORE_OPTIONS} ${CERTIFICATE_OPTIONS} \ 822 | ${X11_OPTION} \ 823 | ${privilegedString} \ 824 | ${USER_VARS} \ 825 | ${ENV_VARS} \ 826 | ${VOLUME_MAP} \ 827 | ${PORT_MAP} \ 828 | ${imageTag} \ 829 | $@ 830 | ;; 831 | 2) 832 | #### 2: VNC/noVNC container build image type 833 | #### ----------------------------------- #### 834 | #### -- VNC_RESOLUTION setup default --- #### 835 | #### ----------------------------------- #### 836 | if [ "`echo $ENV_VARS|grep VNC_RESOLUTION`" = "" ]; then 837 | #VNC_RESOLUTION=1280x1024 838 | VNC_RESOLUTION=1920x1080 839 | ENV_VARS="${ENV_VARS} -e VNC_RESOLUTION=${VNC_RESOLUTION}" 840 | fi 841 | MORE_OPTIONS="${MORE_OPTIONS} ${HOSTS_OPTIONS} " 842 | sudo docker run \ 843 | --name=${instanceName} \ 844 | --restart=${RESTART_OPTION} \ 845 | ${REMOVE_OPTION} ${RUN_OPTION} ${MORE_OPTIONS} ${CERTIFICATE_OPTIONS} \ 846 | ${privilegedString} \ 847 | ${USER_VARS} \ 848 | ${ENV_VARS} \ 849 | ${VOLUME_MAP} \ 850 | ${PORT_MAP} \ 851 | ${imageTag} \ 852 | $@ 853 | ;; 854 | 855 | esac 856 | 857 | 858 | --------------------------------------------------------------------------------