Skip to content

Instantly share code, notes, and snippets.

@xbalaji
Last active February 24, 2021 04:24
Show Gist options
  • Save xbalaji/32ba4b83f370df72dcce3eba32dcea22 to your computer and use it in GitHub Desktop.
Save xbalaji/32ba4b83f370df72dcce3eba32dcea22 to your computer and use it in GitHub Desktop.
docker-utils.sh - linter, jupyter, jenkins, dillinger, swagger, codeserver
# source this file or copy and paste to get the functions in your environment
docker-lint() {
# superlinter from github
# echo "count: $#"
[[ $1 != "-f" ]] && docker run --name superlinter -t --rm -e RUN_LOCAL=true "${@}" -v $PWD:/tmp/lint github/super-linter
[[ $1 == "-f" ]] && docker run --name superlinter -t --rm -e RUN_LOCAL=true "${@:3}" -v $PWD/"${2}":/tmp/lint/"${2}" github/super-linter
}
docker-jupyter() {
# https://hub.docker.com/u/jupyter/
# docker pull jupyter/minimal-notebook
# https://jupyter-docker-stacks.readthedocs.io/en/latest/index.html
docker run -p 8888:8888 jupyter/minimal-notebook
}
docker-sonar() {
# https://docs.sonarqube.org/latest/setup/get-started-2-minutes/
# Log in to http://localhost:9000 with System Administrator credentials (login=admin, password=admin)
docker run -d --name sonarqube -p 9000:9000 sonarqube:community
}
docker-sonar-stop() {
docker stop sonarqube
}
docker-sonar-rm() {
docker rm sonarqube
}
docker-sonar-scan() {
# after starting the server and creating a project (eg. listresources) in the UI above
# for a single file, use as below, for a whole source folder, the filename be omitted
docker run --rm -e SONAR_HOST_URL="http://localhost:9000" -v "${PWD}/list_resources.py:/usr/src/list_resources.py" sonarsource/sonar-scanner-cli -D sonar.projectKey="listresources"
}
docker-jenkins() {
# no wizard, no password just a quick jenkins
docker run --name "jenkins_on_docker" -d -p50000:50000 -p8080:8080 jenkins/jenkins:lts
}
docker-jenkins-minimal() {
# no wizard, no password just a quick jenkins
docker run --name "jenkins_on_docker" -d -p50000:50000 -p8080:8080 -e JAVA_OPTS="-Dhudson.Main.development=true -Djenkins.install.runSetupWizeard=false" jenkins/jenkins:lts
}
docker-jenkins-stop() {
docker stop jenkins_on_docker
}
docker-jenkins-remove() {
docker rm jenkins_on_docker
}
docker-jenkins-hints() {
cat << EOF
mkdir -p "\${HOME}/containers/jenkins"
# user "--rm" if you want to remove container when stopping
docker run --rm --name "jenkins_on_docker" -d -p50000:50000 -p8080:8080 -v "\${HOME}/containers/jenkins:/var/jenkins_home" jenkins/jenkins:lts
docker exec -t jenkins_on_docker cat /var/jenkins_home/secrets/initialAdminPassword
docker exec -i -t jenkins_on_docker /bin/bash
EOF
}
docker-jenkins-no-secure-updatecenter() {
#create update center url config without https (change to http)
cat << EOF > hudson.model.UpdateCenter.xml
<?xml version='1.1' encoding='UTF-8'?>
<sites>
<site>
<id>default</id>
<url>http://updates.jenkins.io/update-center.json</url>
</site>
</sites>
EOF
# now mount and run jenkins with the above config file
docker run --name "jenkins_on_docker" -d -p50000:50000 -p8080:8080 -v $PWD/hudson.model.UpdateCenter.xml:/var/jenkins_home/hudson.model.UpdateCenter.xml jenkins/jenkins:lts
}
docker-codeserver() {
# create the directory to be mounted if necessary or adjust the volume mount point
mkdir -p containers/codeserver
# pull and run codeserver
docker run --name "codeserver" -d -p 8080:8080 -v ${HOME}/containers/codeserver:/home/coder/project:z -u "$(id -u):$(id -g)" codercom/code-server:latest
}
docker-codeserver-getpasswd() {
# get the password and connect to the server at http://<ip-address>:8080
docker exec -t codeserver cat .config/code-server/config.yaml
}
docker-codeserver-stop() {
docker stop codeserver
}
docker-codeserver-remove() {
docker rm codeserver
}
docker-dillinger-markdown-editor() {
docker run -d --name dillinger -p 8090:8080 --restart="always" joemccann/dillinger:3.24.1
}
docker-swagger-api() {
docker run -d --name swagger -p 8080:8080 swaggerapi/swagger-editor
}
docker-utils-show-ipaddress() {
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}: {{.Name}}' $(docker ps -aq) | sort
}
docker-jenkins-blueocean() {
cat << EOF
docker network create jenkins
docker volume create jenkins-docker-certs
docker volume create jenkins-data
docker container run --name jenkins-docker --rm --detach --privileged --network jenkins --network-alias docker --env DOCKER_TLS_CERTDIR=/certs --volume jenkins-docker-certs:/certs/client --volume jenkins-data:/var/jenkins_home --publish 2376:2376 docker:dind
docker container run --name jenkins-blueocean --rm --detach --network jenkins --env DOCKER_HOST=tcp://docker:2376 --env DOCKER_CERT_PATH=/certs/client --env DOCKER_TLS_VERIFY=1 --volume jenkins-data:/var/jenkins_home --volume jenkins-docker-certs:/certs/client:ro --publish 8080:8080 --publish 50000:50000 jenkinsci/blueocean
EOF
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment