-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Useful Docker and kubernates Commmands
- Loading branch information
Showing
6 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
# Docker Useful commands | ||
|
||
- List all the running docker container | ||
|
||
docker ps | ||
- List all the running docker container ID | ||
|
||
docker ps -aq | ||
- List all the images | ||
|
||
docker images ls | ||
- List all the containers | ||
|
||
docker container ls | ||
- Run docker container in a detached mode | ||
|
||
docker run -d [image]:version/tag | ||
docker run -d ngnix:latest | ||
- Running docker container in a detached mode with exposing port | ||
|
||
docker run -d -p host_port:contianer_port [image]:version/tag | ||
docker run -d -p 8080:80 ngnix:latest | ||
- Stopping running docker container | ||
|
||
docker stop [container_id] | ||
- Running docker container in a detached mode with exposing multiple ports | ||
|
||
docker run -d -p host_port:contianer_port -p host_port:contianer_port [image]:version/tag | ||
docker run -d -p 8080:80 -p 3000:80 ngnix:latest | ||
- Removing docker container | ||
|
||
docker rm [container_id] | ||
Note : docker rm will not remove running container, To stop running instance try with flag -f(force), | ||
|
||
docker rm -f [container_id] | ||
docker rm -f $(docker ps -aq) | ||
|
||
Second command will remove all the existing docker container by filtering container_ids | ||
- Creating a docker container with custom name | ||
|
||
docker run --name custom_name -d host_port:contianer_port [image]:version/tag | ||
|
||
docker run --name website -d 8080:80 ngnix:latest | ||
|
||
- Displaying results with formatted style(docker-ps-vertical) | ||
|
||
export FORMAT="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 = $FORMAT | ||
- Pushing our custom html file directly to nginx server | ||
|
||
docker run --name custom_containername -v Source_html_path:Destination_HTML_path:mode -p host_port:contianer_port [image]:version/tag | ||
|
||
docker run --name website -v $(pwd):/usr/share/nginx/html:ro -p 8080:80 ngnix:latest | ||
|
||
mode = ro | ||
ro - only read | ||
|
||
- Executing in a interaction mode in bash | ||
|
||
docker exec -it container-name bash | ||
docker exec -it website bash | ||
- Exitting from bash interaction mode | ||
|
||
exit | ||
|
||
- Creating a new container from the mounted volume | ||
|
||
docker run --name container_name --voulme-from container_name -d -p host_port:contianer_port [image]:version/tag | ||
- Login in to external docker container | ||
|
||
docker login servername | ||
- Inspecting container id | ||
|
||
docker inspect container_id | ||
|
||
- Logging container_id | ||
|
||
docker logs container_id | ||
|
||
- creating dockerfile | ||
|
||
touch Dockerfile | ||
|
||
- Building custom docker image | ||
|
||
docker build --tag website:latest | ||
- Pulling docker image of node-alpine | ||
|
||
docker pull node:alpine | ||
- Setting up the tag for our cusotm build image from present to future tag, which overwrite container name | ||
|
||
docker tag [tag_name_present]:version [tag_name_future]:version | ||
- Removing one or more images of docker | ||
|
||
docker rmi [option] image:tag | ||
--- | ||
# Docker Explanation | ||
|
||
 | ||
|
||
 | ||
|
||
 | ||
|
||
--- | ||
|
||
# Kubernates Useful commands | ||
|
||
To run kubernates, we need minikube and kubectl | ||
|
||
- Running minikube | ||
|
||
minikube start hypervisor --hypervisor | ||
minikube start docker --docker | ||
|
||
- Getting all nodes | ||
|
||
kubectl get nodes | ||
- Getting all pds | ||
|
||
kubectl get pod | ||
- Getting all serivices | ||
|
||
kubectl get services | ||
- Getting all deployments | ||
|
||
kubectl get deployments | ||
- Creating component(a deployment(abstraction ober pods) of pod) | ||
|
||
kubectl create -f file.(yaml) | ||
(or) | ||
kubectl apply -f file.(yaml) | ||
- Getting log of pod | ||
|
||
kubectl logs podname | ||
- Describing pods | ||
|
||
kubectl describe pod pod_name | ||
- Executing interactive pod with bash | ||
|
||
kubectl exec -it pod_name -- bin/bash | ||
- Deleting config file | ||
|
||
kubectl delete -f filename | ||
- Get all pods | ||
|
||
kubectl get all | ||
- Get pod with IP | ||
|
||
kubectl get pod -o wide | ||
|
||
--- | ||
|
||
# Kubernates Explanation | ||
|
||
 | ||
|
||
 | ||
|
||
 | ||
|
||
 | ||
|
||
 | ||
|
||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: mongodb-configmap | ||
data: | ||
database_url: mongodb-service |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: mongo-express | ||
labels: | ||
app: mongo-express | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: mongo-express | ||
template: | ||
metadata: | ||
labels: | ||
app: mongo-express | ||
spec: | ||
containers: | ||
- name: mongo-express | ||
image: mongo-express | ||
ports: | ||
- containerPort: 8081 | ||
env: | ||
- name: ME_CONFIG_MONGODB_ADMINUSERNAME | ||
valueFrom: | ||
secretKeyRef: | ||
name: mongodb-secret | ||
key: mongo-root-username | ||
- name: ME_CONFIG_MONGODB_ADMINPASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: mongodb-secret | ||
key: mongo-root-password | ||
- name: ME_CONFIG_MONGODB_SERVER | ||
valueFrom: | ||
configMapKeyRef: | ||
name: mongodb-configmap | ||
key: database_url | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: mongo-express-service | ||
spec: | ||
selector: | ||
app: mongo-express | ||
type: LoadBalancer | ||
ports: | ||
- protocol: TCP | ||
port: 8081 | ||
targetPort: 8081 | ||
nodePort: 30000 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: mongodb-deployment | ||
labels: | ||
app: mongodb | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: mongodb | ||
template: | ||
metadata: | ||
labels: | ||
app: mongodb | ||
spec: | ||
containers: | ||
- name: mongodb | ||
image: mongo:5.0.1-focal | ||
ports: | ||
- containerPort: 27017 | ||
env: | ||
- name: MONGO_INITDB_ROOT_USERNAME | ||
valueFrom: | ||
secretKeyRef: | ||
name: mongodb-secret | ||
key: mongo-root-username | ||
- name: MONGO_INITDB_ROOT_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: mongodb-secret | ||
key: mongo-root-password | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: mongodb-service | ||
spec: | ||
selector: | ||
app: mongodb | ||
ports: | ||
- protocol: TCP | ||
port: 27017 | ||
targetPort: 27017 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: mongodb-secret | ||
type: Opaque | ||
data: | ||
mongo-root-username: dXNlcm5hbWU= | ||
mongo-root-password: cGFzc3dvcmQ= |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx-deployment | ||
labels: | ||
app: nginx | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: nginx | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx:1.21.1-alpine | ||
ports: | ||
- containerPort: 80 | ||
|