{"id":19622422,"url":"https://github.com/carrington-dev/docker","last_synced_at":"2025-02-26T19:22:12.117Z","repository":{"id":217852957,"uuid":"744958494","full_name":"Carrington-dev/docker","owner":"Carrington-dev","description":"Docker tutorial from beginner to advanced administrator","archived":false,"fork":false,"pushed_at":"2025-01-07T20:18:27.000Z","size":48,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-07T21:24:16.923Z","etag":null,"topics":["data-persistence","docker","dockernetworks","mount","swarm"],"latest_commit_sha":null,"homepage":"https://stemgon.co.za/","language":"Python","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/Carrington-dev.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}},"created_at":"2024-01-18T10:58:38.000Z","updated_at":"2025-01-07T20:18:31.000Z","dependencies_parsed_at":"2024-01-24T12:00:18.733Z","dependency_job_id":"c09ed205-2e6c-4720-93db-86bf0fcd81e9","html_url":"https://github.com/Carrington-dev/docker","commit_stats":null,"previous_names":["carrington-dev/docker"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Carrington-dev%2Fdocker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Carrington-dev%2Fdocker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Carrington-dev%2Fdocker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Carrington-dev%2Fdocker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Carrington-dev","download_url":"https://codeload.github.com/Carrington-dev/docker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240918845,"owners_count":19878505,"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":["data-persistence","docker","dockernetworks","mount","swarm"],"created_at":"2024-11-11T11:27:42.300Z","updated_at":"2025-02-26T19:22:12.076Z","avatar_url":"https://github.com/Carrington-dev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker tutorial for beginners\n\nDocker is a containerized way of running different application with the same or different packages, tooks, source code without affecting one another in a same pc, instance or hypervisor. The docker run time will be the same for all of these docker images provided they are running on the same pc.\n\n# Docker basics\n\n## Running the docker image\nThis is the first way to run a docker image\n```bash\ndocker run -p \u003cpc_port\u003e:\u003cdocker_port\u003e \u003cdocker_image_name\u003e\ndocker run --publish \u003cpc_port\u003e:\u003cdocker_port\u003e \u003cdocker_image_name\u003e\n```\nThe image above will stop if you click `ctrl + c` on your pc\n\n__if you want to run a docker image in the background without interuption use the following command__\n\n```bash\ndocker run -p -d \u003cpc_port\u003e:\u003cdocker_port\u003e \u003cdocker_image_name\u003e\ndocker run --publish --detach \u003cpc_port\u003e:\u003cdocker_port\u003e \u003cdocker_image_name\u003e\n```\n__Note that `-p = --publish` and `-d = --detach`__\n\nExamples are given below\n\n1.  Running a docker-nginx image\n```bash\ndocker run -p -d 8000:80 nginx\n```\n\n2.  Running an apache web server\n```bash\ndocker run -p -d 8000:80 apache\n# could be wrong\n```\n3. Running custom images\n```python\n# will add more notes on this one\n```\n\n## List running containers\nIf you want to see all containers running in your pc use the following commands\n\n```bash\ndcoker containers ls # returns running containers\ndcoker ls\ndcoker ls -a\ndocker ps # this is an old way of doing it but it still works\n```\n`-a means all or irrespective of their status`\n\n## To stop a container\nif you a container is running in the image and you want to stop it use\n```bash\ndocker container stop \u003ccontainer-id\u003e\ndocker stop \u003ccontainer-id\u003e\ndocker container stop \u003ccontainer-name\u003e\ndocker stop \u003ccontainer-name\u003e\ndocker container stop \u003ccontainer-first-four-charectors-on-id\u003e\ndocker stop \u003ccontainer-first-four-charectors-on-id\u003e\n```\n\n## Instances when a container is hidden\nwhen an instance has been stopped it will be hidden to see it use\n```docker ls -a```\n\n## To search images on dockerhub\n\nTo search images on dockerhub \n\n```bash\ndocker search \u003cimage-name\u003e\n```\n\n## To start existing images \nThis will start only existing stopped images\n```bash\ndocker start \u003cimage-name or id\u003e\n```\n\n## To restart existing images \nThis will restart only existing stopped or running images\n```bash\ndocker restart \u003cimage-name or id\u003e\n```\n## Defining a static container name\n\nWhen running a container using `docker run` without providing a name for the container,dcker will create an assign a default name to that container `of some famous scientists` however if you want to assign a name for a container use '--name \u003cname-you-want\u003e'\n\ne.g\n\n```bash\ndocker run -p -d 8000:80 --name \u003cname-you-want\u003e nginx\ndocker run -p -d 8000:80 --name web_server nginx\n```\n\nTo see the result of this use \n\n```bash\ndocker ps\ndocker ps -a\n```\n\n## To see problems or logs on a container\n\n```bash\ndocker logs \u003ccontainer name\u003e\n```\n## To see processes in a container\n\n```bash\ndocker top \u003ccontainer-name\u003e or \u003c container-id\u003e\n```\nalso try this for all\n```bash\nps -ef | grep \u003ccontainer-name\u003e\nps -ef | grep nginx\n```\n\n## To remove or delete a container\n__rm to running containers will give you an error__\n```bash\ndocker rm \u003ccontainer-id\u003e\ndocker rm \u003ccontainer-id\u003e \u003c...id2\u003e \u003cid3\u003e\n```\n\n## Differences between Containers and Virtual Machines\n\n1. They both have resource allocation and allocation benefits but the memory allocation for VMs is static where for containers it's static\n\n2. Containers virtualizes operating systems where as VMs virtualizes hardware\n\n3. Containers are more portable (1 creation multiple execution on different machines)\n\n4. Containers are just processes\n\n5. Contianers are limited to resources they can access\n\n6. Containers can be killed on exit\n\n\n## Execute a container with user supplied arguments\n\n```bash\ndocker run --name custom-mysql -e MYSQL_ROOT_PASSWORD=#Mulalo96 -d mysql\n```\n\n## Docker Monitoring\n\n### Resource Consuption Stats\n\n```bash \ndocker stats \u003ccontainer_name or container_id\u003e\n```\n### Get detail information about a container (running)\n\nGet a detailed information about docker container when running\n```bash \ndocker inspect \u003ccontainer_name or container_id\u003e\n```\n\n## Execute the container in interactive mode\n\n```bash\ndocker run -it \u003cimage_name\u003e \u003ccommands\u003e\n```\n\n-   using -i: means it will keep the stdin open if not attached\n-   using -t: Allow a pseudo-TTY terminal open\n\nexamples \n```bash\ndocker run -it nginx /bin/bash # to access the terminal of the container\ndocker run -it nginx ls\ndocker run -it nginx pwd\n```\n\n__this works when launching only__\n\n\n## Execute the bash commands on container that is already created\n\n```bash\ndocker exec -it \u003cimage-name or id\u003e touch /tmp/carrie\ndocker exec -it \u003cimage-name or id\u003e /bin/bash\n# docker run -it --name mysql_name -e MYSQL_ROOT_PASSWORD=#Mulalo96 mysql -uroot -p\ndocker run -it --name mysql_client -e MYSQL_ROOT_PASSWORD=#Mulalo96 mysql\n```\n\n## To stop all containers\n\n```\ndocker stop $(docker ps -a -q)\n\n```\n## To remove all containers\n\n```bash\ndocker rm $(docker ps -a -q)\ndocker container prune # all stopped containers\ndocker image prune # not tagged latest\n\n```\n\n## Useful commands for Docker\nBefore I leave you, I have prepared a list of commands that may be useful to you on Docker.\n\n### List your images.\n```bash\ndocker image ls\n```\n### Delete a specific image.\n```bash\ndocker image rm [image name]\n```\n### Delete all existing images.\n```\ndocker image rm $(docker images -a -q)\n```\n### List all existing containers (running and not running).\n```bash\ndocker ps -a\n```\n### Stop a specific container.\n```bash\ndocker stop [container name]\n```\n### Stop all running containers.\n```bash\ndocker stop $(docker ps -a -q)\n```\n### Delete a specific container (only if stopped).\n```bash\ndocker rm [container name]\n```\n### Delete all containers (only if stopped).\n```bash\ndocker rm $(docker ps -a -q)\n```\n### Display logs of a container.\n```bash\ndocker logs [container name]\n```\n\n# Docker networks\n\nif you want to connect two instances/containers to run on the same network interface then this is the way.\n\nNetworks connects a container to another container and two containers to a host machine\n\n## Bridge Network\n\nBy default all docker containers are connected to the bridge network which is th default network created by the runtime envrionment. All containers in the bridge network communicate with each other using ip-addresses.Containers on different host machine cannot communicate with each other without additional configuration\n\n## Overlay Network\n\nThis model enables communication between containers from two or more different host machines. Technlogies like VXLAN or IPSec are often used to create virtual machines that span multiple hosts.\n\n## Container Network Interfaces \n\nCNI is a specification that defines how a container runtime interacts with networking plugins. it allows different container runtimes to be combined with various networking solutions.\n\n## To find port of a container\n\n```\ndocker port \u003ccontianer_id\u003e\ndocker port \u003ccontianer_name\u003e\n```\n\n## Find docker container ip\n\n```\ndocker inspect \u003ccontianer_id or name\u003e\n```\nfilter one item\n```bash\ndocker inspect \u003ccontainer_id\u003e -f {{ .key.value }}\n```\n\n## Docker Network CLI Commands\n\n1.  to see all networks are available\n```bash\ndocker network ls\n```\n2. to create a network\n\n```\ndcoker network create my_bridge_net\n```\n\n## To filter networks\n\nTo filter networks in the bridge\n```bash\ndocker network -f drive=bridge\n\n```\n\nTo finds all networks ids and drivers\n\n```bash\ndocker network ls -f \"{{ .ID }}: {{ .Driver }}\"\n```\n\nTry \n```bash\ndocker network --help\n```\n\n## Docker DNS (Domain Name System)\n\nDNS is a system in which domains to thier respective ip addresses\n\nDontainers use DNS to communicate\n\n__can add network to container when run using --network \u003cnetwork_name\u003e__\n\ncheck if containers in the same network are connected\n\n```bash\n\ndocker run -it \u003ccontainer1\u003e ping \u003ccontainer_2\u003e\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarrington-dev%2Fdocker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcarrington-dev%2Fdocker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarrington-dev%2Fdocker/lists"}