Comment on page

Docker and Kubernetes

some docker and k8s commands I don't wanna search over internet
Docker ecosystem
# create an image with a tag from git (courtesy of @ahmetb:
docker build -t website:${git describe --always --tags --dirty} .
# run container
docker run -p 3000:8080 -e NODE_ENV='production' --name website-prod \
--restart=always -d
# access bash inside a running container
docker exec -it container-name bash
# remove all stopped containers
docker rm -v $(docker ps -a -q -f status=exited)
# stop and remove all docker containers
docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)
# remove all docker images
docker rmi $(docker images -a -q)
# prune docker system
docker system prune
# one liner for docker cleanup
docker stop $(docker ps -a -q) && \
docker rm $(docker ps -a -q) && \
docker rmi $(docker images -a -q) && \
docker system prune
function _exit {
kill $(jobs -p)
trap _exit EXIT
for name in $(docker ps --format "{{.Names}}"); do
eval "docker logs -f --tail=5 \"$name\" | sed -e \"s/^/[$name] /\" &";
# to exit logging, bring the process in foreground and exit
# $ fg
# $ Command + C
# from
# all commands:
# get credentials for your gcp cluster
gcloud container clusters get-credentials dev-cluster --zone=us-central1-f
# create a deployment on your cluster
kubectl run website-deployment
# check if deployment was successful
kubectl get deployments
# get pods
kubectl get pods
# scale deployments
kubectl scale deployment website-deployment --replicas=4
# rolling updates
kubectl set image deployments/website-deployment$SHA
# remove evicted pods
kubectl get pods | grep Evicted | awk '{print $1}' | xargs kubectl delete pod
# remove all pods
kubectl delete --all pods
# tail a deployment
kubectl logs deployment/website-deployment --tail 10 -f
# ssh into a pod
kubectl exec -it my-pod -- /bin/bash