DEV Community

technonotes-hacker
technonotes-hacker

Posted on

Kubernetes - Day - 04 - Docker Commands

IMAGES

docker images
Enter fullscreen mode Exit fullscreen mode
  • alpine images & bookworm images ( these are like families ) --> these are small images to be used for 10 mb application rather than going for bigger version of OS.
docker pull ubuntu:noble-20260810
Enter fullscreen mode Exit fullscreen mode


docker ps [ process status ]
ps aux [ process which are running currenlty ]
docker ps [ currently running containers ]
docker ps -a [ provides the list of images which are Exited ]
docker rm $(docker ps -aq)
Enter fullscreen mode Exit fullscreen mode
docker run ubuntu 
docker ps -a [ Now , this will show as Exited ]
Enter fullscreen mode Exit fullscreen mode

Why ? "docker run ubuntu" --> This command didn't tell anythig to do. So it will be EXITED.

docker run ubuntu ls
docker ps -a [ Now , this will show as Exited with ls ]
Enter fullscreen mode Exit fullscreen mode

If you want to create a IMAGE , then there should be always a entry-point.

docker run -d ubuntu bash         [ D for daemon ]
docker run -it ubuntu bash        [ bash is a shell command ]
docker exec -it  <container_id>   [ exec means execute ]
docker run -it ubuntu sleep 10
Enter fullscreen mode Exit fullscreen mode
  • 11 characters will be displayed in container ID.


docker pull redis
docker run redis
In another terminal --> docker ps -a
In another terminal --> docker exec -it <container_id> bash
Enter fullscreen mode Exit fullscreen mode
docker run -d --name webapp-nginx nginx 
docker ps [ it will be showing UP ]
docker exec -it <container_id> bash
docker stop <name or container_id>
Enter fullscreen mode Exit fullscreen mode
  • nginx will run in 80 port by default.
docker run -d --name webapp -p 8090:80 nginx
docker exec -it <container_id> bash
Enter fullscreen mode Exit fullscreen mode

Inside the container --> curl http://localhost:80 --> will get the response.
Outside the container --> curl http://localhost:8090

  • Whatever its inside the container , it gets exposed to the host outside via pot mapped.

Logs

docker logs -f <container_id or name>  [ Continuous logs ]
docker stop <container_id or name>
Enter fullscreen mode Exit fullscreen mode

Bind

docker run -d --name webapp -p 8090:80 -v "./html":"/usr/share/nginx/html" nginx

docker run --rm -d --name webapp -p 8090:80 -v "./html":"/usr/share/nginx/html" nginx [ If the container is stopped , don't wait for my signal , yiu automatically delete it , so only we are using **--rm** ]
Enter fullscreen mode Exit fullscreen mode
docker inspect <container_id or name>
Enter fullscreen mode Exit fullscreen mode
  • There will be one private ip assigned.
  • Run the curl with the private IP , it will load the page.
  • In host , curl http://:80/ & curl http://:8090/

Docker Basic Command

Docker Images Command

Docker Containers Command

Docker Networks Command

Docker Volumes Command

Docker Compose Command

Dockerfile Directives Command

Docker Cleanup Command

Docker Miscellaneous Command

Notes

  • Redis , Postgress --> will have base OS , as these are application.
  • Entry-Point, Command & Expose. --> Important Terminology

Top comments (0)