Last active
February 18, 2022 14:54
-
-
Save debu999/a3d0f8e9538f5c601c82385246815018 to your computer and use it in GitHub Desktop.
Docker and Kubernetes handy commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
New Tutorial | |
Docker is a on OS-level virtualization software platform that enables developers and IT administrators to create, deploy and run applications | |
in a Docker Container with all their dependencies.... | |
Docker Advantages: Rapid deployment / Quick and easy configuration / Better efficiency / Portability / Scalability / Security | |
Docker Image: Instruction Template to create containers. Dockerfile, Multi layered, usually starts with base layer. | |
COMMANDS | |
docker --version / docker version | |
docker run hello-world # to run a image with tag latest | |
docker images | |
docker ps -a / docker ps | |
docker container commit/cp/prune/kill/exec/ls/rm/restart/rename [image] containername/id | |
commit -> new image from change in container | |
cp copy from local to container | |
prune - remove stopped containers | |
kill - kill running container | |
exec - new command in container | |
Docker compose | |
docker-compose up [-d] --scale | |
docker-compose down | |
docker-compose -v | |
Dockerfile | |
FROM: base image | |
PULL: add files to docker image | |
RUN: runs some commands building the container | |
CMD: command to run in container | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DOCKER | |
docker build -f src/main/docker/Dockerfile.graalvm -t graalbase . | |
GRAALBASE | |
FROM ghcr.io/graalvm/graalvm-ce:latest AS build | |
RUN gu install native-image | |
WORKDIR /project | |
VOLUME ["/project"] | |
ENTRYPOINT ["native-image"] | |
Docker container create [OPTINS] IMAGE [COMMAND] [ARG…] | |
docker pull <image>:<tag>: pulls image from DTR | |
docker push <image>:<tag>: pulls image from DTR | |
kubectl create deploy products --image=doogle999/products:native --dry-run=client -o yaml > skaffold.yaml | |
kubectl create -f skaffold.yaml | |
kubectl run nginx --image=nginx --rm -ti --restart=Never -- /bin/sh. (Temporary run of a new image in Kubernetes ) | |
kubectl create -f skaffold-cart.yaml | |
docker run -d --platform linux/amd64 --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:latest | |
98738801110 | |
docker version | |
docker build —tag TAGNAME . ##(This will create the docker image from current directory) | |
docker history TAGNAME | |
docker images | |
docker run -d -p 8080:8080 —name=“CONTAINERNAME” TAGNAME | |
docker ps | |
docker-marine ip | |
docker stop CONTAINERNAME | |
docker container ls -a | |
docker rm CONTAINERNAME | |
docker container prune -f | |
docker rmi IMAGENAME | |
docker rmi TAGNAME | |
docker image prune -af | |
docker start CONTAINERNAME | |
docker ps -a | |
docker rm containerid #single delete | |
docker rm $(docker ps -aq) #remove all | |
docker rm -f $(docker ps -aq) #remove all force fully | |
docker -v | |
docker ps # list all active container | |
docker container ls # list all containers active | |
docker images # list all images | |
docker image ls # list all images | |
## container is a running instance of an image | |
docker pull nginx:latest # to pull a image to local | |
docker run -dit --name img1 -p8080:80 -p8081:80 nginx:latest # create a img1 named docker local image running for nginx | |
export fmt="ID\t{{.ID}}\nNAME\t{{.Names}}\nIMAGE\t{{.Image}}\nPORTS\t{{.Ports}}\nCOMMAND\t{{.Command}}\nCREATED\t{{.CreatedAt}}\nSTATUS\t{{.Status}}\n" | |
docker ps --format ${fm} | |
## Volume in docker | |
docker run --name website -p8080:80 -dit nginx:latest -v $(pwd):/usr/share/nginx/html:ro /bin/bash #detached #it is interactive and ro mount | |
docker run --name website -p8080:80 -dit nginx:latest -v $(pwd):/usr/share/nginx/html /bin/bash #detached #it is interactive and rw mount | |
docker run --name website-copy --volume-from websit -d -p 8081:80 nginx | |
## build docker | |
docker build -tag web-nginx:latest . | |
## alpine is for smaller linux distribution | |
docker image rm # to remove a image or docker rmi website # bot works | |
docker image ls # list all images in local | |
images have repository and tag | |
docker tag web-nginx:latest web-nginx:1 | |
docker build -tag web-nginx:latest . | |
docker tag web-nginx:latest web-nginx:2 | |
and so we have all the version tagged and can be used as needed. | |
docker inspect containerid / docker inspect container-name | |
docker logs containerid / docker logs container-name | |
docker exec -it containerid /bin/bash # to enter into a container | |
KUBERNETES | |
Master can have replicas as well in prod!!! | |
- Api Server | |
- Controller Manager | |
- Scheduler | |
- etcd | |
Virtual Network - all worker nodes | |
Pod = layer on top of container viz. docker container (Smallest unit of k8s) | |
Pod have one app + some side cars its a abstraction over container | |
Each pod have one private ip in cluster. | |
service: lifecycle of service and pod are not connected | |
ingress: open to external service | |
egress: open to internal services | |
config map: key value pair can be mounted as file or properties or env variable | |
secret: same as config map but is base64 encoded data | |
Volumes: local machine or remote viz. cloud storage | |
Deployment stateful - Replicas can be set in deployment.yml | |
deployment -> pods -> container | |
statefulset should be used to host db/elasticsearch/storate etc. | |
kubectl get nodes | |
kubectl version | |
kubectl create deployment NAME --image=image [dry-run] [options] | |
kubectl describe pod podname | |
kubectl logs podname | |
kubectl get nodes/pods/services/replicaset/deployments | |
kubectl describe nodes/pods/services/replicaset/deployments | |
kubectl config view | |
kubectl apply -f filename.yml # apply a file | |
kubectl config get-contexts | |
kubectl config use-context docker-for-desktop | |
kubectl -n kubernetes-dashboard get secret $(kubectl -n kubernetes-dashboard get sa/admin-user -o jsonpath="{.secrets[0].name}") -o go-template="{{.data.token | base64decode}}" | |
kubectl get all | |
kubectl get pod | |
kubectl get pod --watch to watch its updates | |
kubectl get pod mongodb-deployment-79df5cb449-r7hh2 -o wide / get pod -o wide | |
kubectl describe service mongodb-service | grep -i "ip:\|Endpoints:" | |
kubectl config use-context docker-for-desktop | |
kubectl cluster-info | |
kubectl get nodes | |
kubectl get svc | |
kubectl wait --namespace ingress-nginx \ | |
--for=condition=ready pod \ | |
--selector=app.kubernetes.io/component=controller \ | |
--timeout=120s | |
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.0.3/deploy/static/provider/cloud/deploy.yaml | |
kubectl get pods -n ingress-nginx \ | |
-l app.kubernetes.io/name=ingress-nginx --watch | |
POD_NAMESPACE=ingress-nginx | |
POD_NAME=$(kubectl get pods -n $POD_NAMESPACE -l app.kubernetes.io/name=ingress-nginx --field-selector=status.phase=Running -o jsonpath='{.items[0].metadata.name}') | |
kubectl exec -it $POD_NAME -n $POD_NAMESPACE -- /nginx-ingress-controller --version | |
kubectl apply -f admin_user.yml | |
kubectl apply -f role_admin_user.yml | |
kubectl -n kubernetes-dashboard get secret $(kubectl -n kubernetes-dashboard get sa/admin-user -o jsonpath="{.secrets[0].name}") -o go-template="{{.data.token | base64decode}}" | |
kubectl proxy & | |
## ACCESS DASHBOARD | |
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ | |
## NEW STUFFS | |
docker version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
New Data