Skip to content

Instantly share code, notes, and snippets.

@Dizolivemint
Last active November 17, 2021 23:52
Show Gist options
  • Save Dizolivemint/7c5e29ab6e338c55ddb75db19934d6a1 to your computer and use it in GitHub Desktop.
Save Dizolivemint/7c5e29ab6e338c55ddb75db19934d6a1 to your computer and use it in GitHub Desktop.
Docker Commands

Docker

docker build . will run the Dockerfile to create an image
docker build . -t [Dockerhub-username]/[image-name]:[v1] build an image with a specific version
docker push [Dockerhub-username]/[image-name][v1] push to dockerhub
docker images will print all the available images
docker run {IMAGE_ID} will run a container with the image
docker run -d {IMAGE_ID} will run a container with the image in the background
docker ps will print all the running containers
docker kill {CONTAINER_ID} will terminate the container

Open bash into a particular container
docker exec -it <container-id> bash
Navigate to the specific file to ensure that your edits are there.
cat <qualified-filename>

Viewing Logs
docker logs

Attaching to a Container
docker exec -it sh

View Docker Processes
docker ps

Include dead containers
docker ps -a

View Details of Docker Objects
docker inspect

Docker Compose

Make sure the Docker services are running in your local machine
Remove unused and dangling images
docker image prune --all Run this command from the directory where you have the "docker-compose-build.yaml" file present
docker-compose -f docker-compose-build.yaml build --parallel
Run the docker image
docker-compose up
Check env variables
docker-compose config
Stop docker compose
docker-compose down --remove-orphans
To delete all dangling images
docker image prune --all

EKSCTL to auto provision a cluster
eksctl create cluster --name myCluster --region=us-west-1 --nodes-min=2 --nodes-max=3

Once you get the success confirmation, run
kubectl get nodes

Describe stacks
eksctl utils describe-stacks --region=us-west-1 --cluster=myCluster

List all services running in your cluster.
kubectl get svc --all-namespaces
Delete any services that have an associated EXTERNAL-IP value. These services are fronted by an Elastic Load Balancing load balancer, and you must delete them in Kubernetes to allow the load balancer and associated resources to be properly released.
kubectl delete svc <service-name>
Delete the cluster and its associated nodes with the following command, replacing with your cluster name.
eksctl delete cluster --name <prod> Inspect a pod
kubectl logs <podname>

Apply env variables and secrets
kubectl apply -f aws-secret.yaml
kubectl apply -f env-secret.yaml
kubectl apply -f env-configmap.yaml
Remove env variables and secrets
kubectl delete -f <config.yaml>
Deployments - Double check the Dockerhub image name and version in the deployment files
kubectl apply -f deployment.yaml
Service
kubectl apply -f service.yaml

Expose IP

Check the deployment names and their pod status
kubectl get deployments
Create a Service object that exposes the frontend deployment
The command below will ceates an external load balancer and assigns a fixed, external IP to the Service.
kubectl expose deployment frontend --type=LoadBalancer --name=publicfrontend
Check name, ClusterIP, and External IP of all deployments
kubectl get services
kubectl get pods It should show the STATUS as Running
For more info, refer to this tutorial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment