Docker ecosystem
# create an image with a tag from git (courtesy of @ahmetb: https://twitter.com/ahmetb/status/1154882328813924352)docker build -t website:${git describe --always --tags --dirty} .# run containerdocker run -p 3000:8080 -e NODE_ENV='production' --name website-prod \--restart=always -d gcr.io/ivikramtiwari/website:prod# access bash inside a running containerdocker exec -it container-name bash# remove all stopped containersdocker rm -v $(docker ps -a -q -f status=exited)# stop and remove all docker containersdocker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)# remove all docker imagesdocker rmi $(docker images -a -q)# prune docker systemdocker system prune# one liner for docker cleanupdocker stop $(docker ps -a -q) && \docker rm $(docker ps -a -q) && \docker rmi $(docker images -a -q) && \docker system prune
#!/bin/bashfunction _exit {kill $(jobs -p)}trap _exit EXITfor name in $(docker ps --format "{{.Names}}"); doeval "docker logs -f --tail=5 \"$name\" | sed -e \"s/^/[$name] /\" &";donewait# to exit logging, bring the process in foreground and exit# $ fg# $ Command + C# from https://stackoverflow.com/a/54917272/1724300
Kubernetes
deployments-using-kubectl.sh# all commands: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands# get credentials for your gcp clustergcloud container clusters get-credentials dev-cluster --zone=us-central1-f# create a deployment on your clusterkubectl run website-deployment --image=gcr.io/ivikramtiwari/website# check if deployment was successfulkubectl get deployments# get podskubectl get pods# scale deploymentskubectl scale deployment website-deployment --replicas=4# rolling updateskubectl set image deployments/website-deployment website-deployment=gcr.io/ivikramtiwari/website@sha256:$SHA# remove evicted podskubectl get pods | grep Evicted | awk '{print $1}' | xargs kubectl delete pod# remove all podskubectl delete --all pods# tail a deploymentkubectl logs deployment/website-deployment --tail 10 -f# ssh into a podkubectl exec -it my-pod -- /bin/bash