{"id":20453889,"url":"https://github.com/dubaishoaib/docker_notes","last_synced_at":"2026-04-13T03:43:47.364Z","repository":{"id":165681794,"uuid":"641080115","full_name":"dubaishoaib/DOCKER_NOTES","owner":"dubaishoaib","description":"Docker, Docker Compose, SWARM, Kubernetes, DevOps, Linux, ","archived":false,"fork":false,"pushed_at":"2023-05-16T04:06:49.000Z","size":16013,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-05T10:14:18.027Z","etag":null,"topics":["docker","docker-compose","docker-container","docker-image","kubernetes"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dubaishoaib.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-15T18:30:30.000Z","updated_at":"2023-09-21T19:34:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"d2714c71-48b2-4a2f-bb02-388c2666b324","html_url":"https://github.com/dubaishoaib/DOCKER_NOTES","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dubaishoaib/DOCKER_NOTES","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubaishoaib%2FDOCKER_NOTES","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubaishoaib%2FDOCKER_NOTES/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubaishoaib%2FDOCKER_NOTES/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubaishoaib%2FDOCKER_NOTES/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dubaishoaib","download_url":"https://codeload.github.com/dubaishoaib/DOCKER_NOTES/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubaishoaib%2FDOCKER_NOTES/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264002149,"owners_count":23542379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-compose","docker-container","docker-image","kubernetes"],"created_at":"2024-11-15T11:14:16.666Z","updated_at":"2025-10-15T23:49:27.427Z","avatar_url":"https://github.com/dubaishoaib.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DOCKER PRACTICE NOTES\r\n\r\n## Docker Commands\r\n\r\n* Run docker image\r\n```\r\ndocker run nginx\r\n```\r\n\r\n* Pull/Download image\r\n```\r\ndocker pull mysql\r\n```\r\n\r\n* Stop container\r\n```\r\ndocker stop container-id\r\n```\r\n\r\n* List processes\r\n```\r\ndocker ps \r\ndocker ps -a\r\n```\r\n\r\n### Interactive Terminal mode (it) \r\n* (i)Keep STDIN open even if not attached \r\n* (t) Allocate a pseudo-TTY\r\n```\r\ndocker run -it mysql \r\n```\r\n\r\n* Mapping external volume\r\n```\r\ndocker run -v /opt/datadir:/var/lib/mysql mysql\r\n```\r\n\r\n* Run docker image with environment variable\r\n```\r\ndocker run --name some-mysql -e MYSQL_ROOT_PASSWORD=password -d mysql\r\n```\r\n\r\n* Run container and execute command when exit container\r\n```\r\ndocker run ubuntu cat /etc/*release*\r\n```\r\n\r\n* Attach to running container\r\n```\r\ndocker attach container-id\r\n```\r\n\r\n* Docker Run with Volume and Port Forwarding\r\n```\r\ndocker run -p 8080:8080 -p 50000:50000 --restart=on-failure -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts-jdk11\r\n```\r\n\r\n* Docker inpspect to view docker container properties\r\n```\r\ndocker inspect cotanier-id/name\r\n```\r\n\r\n* Override entrypoint \r\n```\r\ndocker run --entrypoint sleep2.0 ubuntu-sleeper 10\r\n```\r\n\r\n* Docker run name the container\r\n* docker run --links to link two container via a command line\r\n```\r\ndocker run -d --name=redis redis\r\ndocker run -d -e POSTGRES_PASSWORD=password -e POSTGRES_HOST_AUTH_METHOD=trust --name=db postgres\r\ndocker run -d --name=vote -p 5000:80 --link redis:redis voting-app\r\ndocker run -d --name=result -p 5001:80 --link db:db result-app\r\ndocker run -d --name=worker --link redis:redis --link db:db worker\r\n```\r\n\r\n## Setting up docker private registry\r\nhttps://github.com/rchidana/Docker-Private-Registry/\r\n```\r\nsudo docker run -d -p 5000:5000 --restart=always --name registry -v /certificates:/certificates -e REGISTRY_HTTP_TLS_CERTIFICATE=/certificates/domain.crt -e REGISTRY_HTTP_TLS_KEY=/certificates/domain.key registry:2\r\n```\r\n\r\n* Docker file build by filename\r\n```\r\ndocker build . -f Dockerfile2 -t tagName\r\n```\r\n\r\n* Docker image disk consumption by Images, Containers, Local Volumes, Build Cache.\r\n```\r\n\u003e docker system df\r\nTYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE\r\nImages          4         0         563.8MB   563.8MB (100%)\r\nContainers      0         0         0B        0B\r\nLocal Volumes   0         0         0B        0B\r\nBuild Cache     0         0         0B        0B\r\n```\r\n\r\n* To view all the images and space consumption use -v flag.\r\n```\r\n\u003e docker system df -v\r\n\r\nImages space usage:\r\n\r\nREPOSITORY         TAG       IMAGE ID       CREATED          SIZE      SHARED SIZE   UNIQUE SIZE   CONTAINERS\r\nmy-color-webapp    latest    39b2b5a6cccb   14 minutes ago   563.8MB   563.8MB       308B          0\r\nmy-simple-webapp   latest    2cc63189dffc   4 hours ago      563.8MB   563.8MB       254B          0\r\nubuntu             latest    6b7dfa7e8fdb   8 days ago       77.8MB    77.8MB        0B            0\r\nhello-world        latest    feb5d9fea6a5   14 months ago    13.26kB   0B            13.26kB       0\r\n\r\nContainers space usage:\r\n\r\nCONTAINER ID   IMAGE     COMMAND   LOCAL VOLUMES   SIZE      CREATED   STATUS    NAMES\r\n\r\nLocal Volumes space usage:\r\n\r\nVOLUME NAME   LINKS     SIZE\r\n\r\nBuild cache usage: 0B\r\n\r\nCACHE ID   CACHE TYPE   SIZE      CREATED   LAST USED   USAGE     SHARED\r\n```\r\n\r\n* Docker orchestration\r\n```\r\ndocker service create --replicas=100 nodejs\r\n```\r\n\r\nusefull linux commands\r\n```\r\n\u003e docker stats\r\n\u003e uptime\r\n\u003e free -m\r\n\u003e df -h\r\n\u003e cat /proc/cpuinfo\r\n\u003e reboot\r\n\u003e shutdown now\r\n\u003e while :; do echo 'Hello World'; done\r\n\u003e fallocate\r\n\u003e truncate\r\n\u003e dd\r\n```\r\n\r\n## Docker Capabilities and no-new-privileges\r\n\r\n```console\r\n\u003e docker run -it -u $(id -u) --security-opt no-new-privileges -v `pwd`:/exploit ubuntu bash\r\n```\r\n\r\n[Docker Capabilities and no-new-privileges\r\n](https://raesene.github.io/blog/2019/06/01/docker-capabilities-and-no-new-privs/)\r\n\r\n\u003e --security-opt=no-new-privlileges this prevents the exploit from executing.\r\n\r\n```console\r\n\u003e docker run -it -u $(id -u) --security-opt no-new-privlileges -v `pwd`:/exploit ubuntu bash\r\n```\r\n\r\n## To count number of packages in linux\r\n\r\n```\r\n\u003e dpkg -l | wc -l\r\n```\r\n\r\n## List last run docker process\r\n```\r\n\u003e docker ps -l\r\nCONTAINER ID   IMAGE            COMMAND                  CREATED          STATUS          PORTS     NAMES\r\n89d71fe62ae9   jpetazzo/clock   \"/bin/sh -c 'while d…\"   15 seconds ago   Up 14 seconds             youthful_villani\r\n```\r\n\r\n## Short form of docker processes\r\n```\r\n\u003e docker ps -q\r\n89d71fe62ae9\r\n2591cb1dd248\r\n24731652b6db\r\n```\r\n\r\n## Last Docker process started.\r\n```\r\n\u003e docker ps -ql\r\n89d71fe62ae9\r\n```\r\n\r\n## Docker logs\r\n### Docker logs tail last 3 lines\r\n```\r\n\u003e docker logs --tail 3 068\r\n```\r\n\r\n### Docker logs for last docker container \r\n```\r\n\u003e docker logs $(docker ps -ql)\r\n```\r\n\r\n### Docker logs for last docker container \r\n```\r\n\u003e docker logs $(docker ps -ql)\r\n```\r\n\r\n### Follow logs runtime\r\n```\r\n\u003e docker logs --tail 10 --follow $(docker ps -ql)\r\n```\r\n\r\n## docker Stop and docker kill\r\n If after 10 sec of docker stop container is still runnning than it will send kill signal to exit the container forcefully.\r\n\r\n## Process tree\r\n```\r\n\u003e ps faux\r\n```\r\n\r\n## Detaching from container\r\nuse ^P^Q in sequence. Otherwise ^C will detach and kill the terminal.\r\n* -t means \"allocate me a terminal\"\r\n* -i means \"connect stdin to the terminal\"\r\nREPL Read Eval Print loop. When attaching to REPL container the shell doesnot know what you just attached so ENTR or ^L will print the shell.\r\n\r\n## Docker search registry online\r\ndocker search zookeeper\r\n\r\n## Creating docker file from exsiting run instance.\r\n```\r\n\u003e docker commit image-id image-tag-name \r\n```\r\n\r\n## Creating tag of an image if not provided proper tag name.\r\n```\r\n\u003e docker tag 105e8294a29b ubu-figlet\r\n```\r\n\r\n## Finding difference between the container base image and the current state of the container.\r\n```\r\n\u003e docker diff contaier-id\r\n```\r\n\r\n## Docker Inspect\r\n```\r\n\u003e docker inspect ticktock | less\r\n```\r\n\r\n## Give Container running status True or False\r\n```\r\n\u003e docker inspect --format '{{.State.Running}}' ticktock\r\n```\r\n\r\n## Port Mapping\r\n  * A simple, static web-server\r\n  ```\r\n  \u003e docker run -d -P nginx\r\n  ```\r\n  * -d tells Docker to run image in background\r\n  * -P tells Docker to make this service reachable from other Computers. -P is  short-version of --publish-all\r\n  ```\r\n  \u003e docker ps -a \r\n  CONTAINER ID   IMAGE             COMMAND                  PORTS                                  \r\n  7987bb3c5c24   nginx             \"/docker-entrypoint.…\"   0.0.0.0:49153-\u003e80/tcp, :::49153-\u003e80/tcp\r\n  ```\r\n  * 0.0.0.0:49153-\u003e80/tcp, :::49153-\u003e80/tcp means web server is running on port 80 inside container\r\n  * That ports is mapped to port 49153 on Docker host\r\n  * Manual allocation of port numbers\r\n  ```\r\n  \u003e docker run -d -p 80:80 nginx\r\n  \u003e docker run -d -p 8000:80 nginx\r\n  \u003e docker run -d -p 8080:80 -p 8888:80 nginx\r\n  ```\r\n  * The convention is port-on-host:port-on-container\r\n\r\n## List all the running containers ID\r\n```\r\n\u003e docker ps -q\r\n```\r\n## Kill all the running dockers\r\n```\r\n\u003e docker ps -q | xargs docker kill\r\n```\r\n\r\n## Start the redis container\r\n```\r\n\u003e docker run --name red28 -d redis:2.8\r\n```\r\n\r\n## This is alpine container running in same network stack as redis network.\r\n```\r\n\u003e docker run --net container:red28 -ti alpine sh\r\n\u003e apk add busybox-extras\r\n```\r\n\r\n## Connect to the redis server on localhost\r\n```\r\n\u003e telnet localhost 6379\r\n\u003e INFO SERVER\r\n\u003e SET PLACE DXB\r\n\u003e SAVE\r\n\u003e QUIT\r\n\u003e docker stop red28\r\n# Reusing red28 volume on new redis container of other version.\r\n\u003e docker run --volumes-from red28 -d --name red30 redis:3.0\r\n\u003e docker run --net container:red30 -ti alpine sh\r\n```\r\n\r\n## Not an init system\r\n```\r\n\u003e sudo systemctl status docker\r\n```\r\nAs two general rules, you shouldn't install software inside running containers \r\n(it will get lost as soon as your container exits), and commands like systemctl just don't work inside Docker. You might think of Docker as a way to package an application and not like a full-blown VM with an init system and users and processes\r\n\r\n## Search \r\n```\r\n\u003e docker search --filter is-official=true mysql\r\n\u003e docker search --limit 7 mysql\r\n\u003e docker search --format \"table {{.Name}}\\t{{.Description}}\\t{{.IsOfficial}}\" --limit 10 --no-trunc mysql\r\n```\r\n\r\n## Registry\r\n```\r\n\u003e docker run -d --name registry -p 5000:5000 --restart=always registry\r\n\u003e docker pull busybox\r\n\u003e docker tag busybox:latest localhost:5000/my-busybox\r\n\u003e docker push localhost:5000/my-busybox\r\n\u003e docker rmi localhost:5000/my-busybox\r\n\u003e docker pull localhost:5000/my-busybox\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdubaishoaib%2Fdocker_notes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdubaishoaib%2Fdocker_notes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdubaishoaib%2Fdocker_notes/lists"}