Wednesday, September 11, 2019

Docker - Creating Containers

docker container run --help

docker container run busybox

docker container ls

docker container ls -a

docker container run --rm busybox

docker container ls -a

docker container run nginx

docker container run -d nginx

docker container ls

docker container ls -a

docker container run -it busybox

# ls
# exit

docker container prune -f

docker container run --name my_busybox busybox

docker container ls -a

===Summary===
docker container run:
  • --help Print usage
  • --rm Automatically remove the container when it exits
  • -d, --detach Run container in background and print container ID
  • -i, --interactive Keep STDIN open even if not attached
  • --name string Assign a name to the container
  • -p, --publish list Publish a container's port(s) to the host
  • -t, --tty Allocate a pseudo-TTY
  • -v, --volume list Mount a volume (the bind type of mount)
  • --mount mount Attach a filesystem mount to the container
  • --network string Connect a container to a network (default "default")
Create a container and attach to it:
docker container run –it busybox
Create a container and run it in the background:
docker container run –d nginx
Create a container that you name and run it in the background:
docker container run –d –name myContainer busybox

Docker Commands

docker -h | more

docker image -h

docker image ls -h

docker image ls

docker image pull nginx


docker image ls

docker image inspect image_id

docker container -h

docker container ls

docker container run busybox

docker container ls

docker container ls -a

docker container run -P -d nginx

docker container ps

docker container inspect container_id

curl http://172.17.0.2

docker container inspect container_id

docker container top container_id

docker container ls
docker container attach container_id

docker container ls

docker container ls -a

docker container start container_id

docker container ls

docker container stop container_id
docker container start container_id

docker container logs container_id

docker container ls

curl localhost:32774

docker container logs container_id

docker container ls

docker container stats container_id

docker container exec -it container_id /bin/bash

# ls
# ls /usr/share/nginx/html/
# exit

docker container ls

docker container exec -it container_id ls /usr/share/nginx/html/

docker container ls

docker container pause container_id

docker container ls

docker container unpause container_id


docker container ls -a

docker container rm -f container_id

docker container ls -a

docker container prune

docker container ls -a

docker container prune -h

docker container prune -f

===Summary===
Get a list of all of the Docker commands:
docker -h

Management command were introduced in Docker engine v1.13

Management Commands:
  • builder Manage builds
  • config Manage Docker configs
  • container Manage containers
  • engine Manage the docker engine
  • image Manage images
  • network Manage networks
  • node Manage Swarm nodes
  • plugin Manage plugins
  • secret Manage Docker secrets
  • service Manage services
  • stack Manage Docker stacks
  • swarm Manage Swarm
  • system Manage Docker
  • trust Manage trust on Docker images
  • volume Manage volumes
docker image:
  • build Build an image from a dockerfile
  • history Show the history of an image
  • import Import the contents from a tarball to create a filesystem image
  • inspect Display detailed information on one or more images
  • load Load an image from a tar file or STDIN
  • ls List images
  • prune Remove unused images
  • pull Pull an image or a repository from a registry
  • push Push an image or a repository to a registry
  • rm Remove one or more images
  • save Save one or more images to a tar file (streamed to STDOUT by default)
  • tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
docker container:
  • attach Attach local standard input, output, and error streams to a running container
  • commit Create a new image from a container's changes
  • cp Copy files/folders between a container and the local filesystem
  • create Create a new container
  • diff Inspect changes to files or directories on a container's filesystem
  • exec Run a command in a running container
  • export Export a container's filesystem as a tar archive
  • inspect Display detailed information on one or more containers
  • kill Kill one or more running containers
  • logs Fetch the logs of a container
  • ls List containers
  • pause Pause all processes within one or more containers
  • port List port mappings or a specific mapping for the container
  • prune Remove all stopped containers
  • rename Rename a container
  • restart Restart one or more containers
  • rm Remove one or more containers
  • run Run a command in a new container
  • start Start one or more stopped containers
  • stats Display a live stream of container(s) resource usage statistics
  • stop Stop one or more running containers
  • top Display the running processes of a container
  • unpause Unpause all processes within one or more containers
  • update Update configuration of one or more containers
  • wait Block until one or more containers stop, then print their exit codes

Friday, March 15, 2019

Kubernetes Reference

Kubernetes Reference

Minikube

minikube start

minikube stop

minikube delete

minikube env

minikube ip



---
Kubectl

kubectl get all
Pods, ReplicaSets, Deployments and Services

kubectl apply –f <yaml file>

kubectl apply –f .

kubectl describe pod <name of pod>

kubectl exec –it <pod name> <command>

kubectl get <pod | po | service | svc | rs | replicaset | deployment | deploy>

kubectl get po --show-labels

kubectl get po --show-labels -l {name}={value}

kubectl delete po <pod name>

kubectl delete po --all



---
Deployment Management

kubectl rollout status deploy <name of deployment>

kubectl rollout history deploy <name of deployment>

kubectl rollout undo deploy <name of deployment>

Docker Reference

Docker Reference

Manage images

docker image pull <image name>

docker image ls

docker image build -t <image name> .

docker image push <image name>

docker image tag <image id> <tag name>



---
Manage Containers

docker container run -p <public port>:<container port> <image name>

docker container ls -a

docker container stop <container id>

docker container start <container id>

docker container rm <container id>

docker container prune

docker container run -it <image name>

docker container run -d <image name>

docker container exec -it <container id> <command>

docker container exec -it <container id> bash

docker container logs -f <container id>

docker container commit -a "author" <container id> <image name>



---
Manage your (local) Virtual Machine

docker-machine ip



---
Manage Networks

docker network ls

docker network create <network name>



---
Manage Volumes

docker volume ls

docker volume prune

docker volume inspect <volume name>

docker volume rm <volume name>



---
Docker Compose

docker-compose up

docker-compose up -d

docker-compose logs -f <service name>

docker-compose down



---
Manage a Swarm

docker swarm init (--advertise-addr <ip address>)

docker service create <args>

docker network create --driver overlay <name>

docker service ls

docker node ls

docker service logs -f <service name>

docker service ps <service name>

docker swarm join-token <worker|manager>



---
Manage Stacks

docker stack ls

docker stack deploy -c <compose file> <stack name>

docker stack rm <stack name>



Thursday, March 14, 2019

ElasticSearch PUT and GET data

--Create an index in Elasticsearch

PUT http://host-1:9200/my_index

{
"settings" : {
"number_of_shards" : 3,
"number_of_replicas" : 1
}
}

--To get information about an index

GET http://host-1:9200/my_index


--Add user to index with id 1

POST http://host-1:9200/my_index/user/1

{
"name": "Deepak",
"age": 36,
"department": "IT",
"address": {
"street": "No.123, XYZ street",
"city": "Singapore",
"country": "Singapore"
}
}

--To fetch document with id 1

GET http://host-1:9200/my_index/user/1

--Add user to index with id 2

POST http://host-1:9200/my_index/user/2

{
"name": "McGiven",
"age": 30,
"department": "Finance"
}

--Add user to index with id 3

POST http://host-1:9200/my_index/user/3

{
"name": "Watson",
"age": 30,
"department": "HR",
"address": {
"street": "No.123, XYZ United street",
"city": "Singapore",
"country": "Singapore"
}
}

--Search documents by name

GET http://host-1:9200/my_index/user/_search?q=name:watson

--Delete an index

DELETE http://host-1:9200/my_index