{"id":22893876,"url":"https://github.com/uzair120/dockerdoc","last_synced_at":"2026-04-29T00:02:51.735Z","repository":{"id":230786649,"uuid":"780174404","full_name":"uzair120/DockerDoc","owner":"uzair120","description":"Docker Course content of KodeKlode. It contain all commands to use docker in your daily usecases.. ","archived":false,"fork":false,"pushed_at":"2024-05-22T21:11:40.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-07T01:27:05.300Z","etag":null,"topics":["docker","docker-compose"],"latest_commit_sha":null,"homepage":"","language":null,"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/uzair120.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":"2024-03-31T22:38:19.000Z","updated_at":"2024-08-22T20:13:54.000Z","dependencies_parsed_at":"2024-05-22T22:24:19.632Z","dependency_job_id":"79c141bf-eec6-415d-8d29-458dfcb9864b","html_url":"https://github.com/uzair120/DockerDoc","commit_stats":null,"previous_names":["uzair120/dockerdoc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uzair120%2FDockerDoc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uzair120%2FDockerDoc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uzair120%2FDockerDoc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uzair120%2FDockerDoc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uzair120","download_url":"https://codeload.github.com/uzair120/DockerDoc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246552975,"owners_count":20795835,"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"],"created_at":"2024-12-13T23:16:10.462Z","updated_at":"2026-04-29T00:02:51.705Z","avatar_url":"https://github.com/uzair120.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# DockerDoc\nAll the commands for running Docker on a server.\n\n## Docker has three main components:\n1. Image\n2. Container (inactive)\n3. Container (active)\n\nAn image is a blueprint of a container, similar to how a class is for an object. Whenever we create a container, we need an image. Therefore, an image is required to create a container, and a container is required to run an instance of an image/container.\n\nWe have the `Jenkins` image in Docker's official docs.\n\n### Creation\nTo download an image:\n```bash\ndocker pull jenkins\n```\n\nTo run the container:\n```bash\ndocker run jenkins\n```\n\n***Note: You can run only the second command to download and run a container at the same time.***\n\nTo see all the running containers:\n```bash\ndocker ps\n```\n\nTo see all the containers with status active or inactive:\n```bash\ndocker ps -a\n```\n\n### Deletion\nTo delete a container, you need to stop any running (active) container, then delete the inactive container, and finally delete the image.\n\nTo stop a running container:\n```bash\ndocker stop \u003ccontainer-id\u003e\n```\n\nTo delete a container:\n```bash\ndocker rm \u003ccontainer-id\u003e\n```\n\nTo delete an image:\n```bash\ndocker rmi \u003cimage-name\u003e\n```\n\nTo give arguments to a container, you can append them at the end of the command:\nFor example, to sleep a container for 10 seconds:\n```bash\ndocker run ubuntu sleep 10\n```\n\nTo provide environment variables to a container, use the `-e` flag before the name:\n```bash\ndocker run -e NODE_ENV=development webapp\n```\n\nTo tag/name a container, use `--tag` or `-t`:\n```bash\ndocker run -t MyPersonalWebApp webapp\n```\n\nTo inspect or check the details of an image or container:\n```bash\ndocker inspect \u003ccontainer-name/image-name/id\u003e\n```\n\nDocker uses a `Dockerfile` to create a custom image from a local machine.\n\nLet's suppose we have a Dockerfile:\n```Dockerfile\nFROM node:18\nRUN mkdir -p /opt/app\nWORKDIR /opt/app\nCOPY src/package.json src/package-lock.json .\nRUN npm install\nCOPY src/ .\nEXPOSE 3000\nENTRYPOINT [\"npm\", \"start\"]\n```\n\nIn the above code:\n1. We are using the Node.js 18 image to create a custom image.\n2. Copying all the code to the working directory of the container.\n3. Running `npm install` to install `npm` packages.\n4. Using port `3000` to connect.\n5. Running the `npm start` command to start the application.\n\n#### Difference between `ENTRYPOINT` and `CMD` in a Dockerfile:\n`ENTRYPOINT` appends arguments at the end of the command specified in the JSON array. \nFor example:\nDockerfile\n```Dockerfile\n...\nENTRYPOINT [\"npm\", \"start\"]\n```\nWhen we run this Dockerfile with some arguments like:\n```bash\ndocker run mywebapp sleep 45\n```\nThe system appends `sleep 45` at the end of the command `npm start`:\n```bash\nnpm start sleep 45\n```\n\nOn the other hand, in the case of `CMD`:\n```Dockerfile\n...\nCMD [\"npm\", \"start\"]\n```\nWhen we run the above command, it will override the existing command and run only the arguments:\n~~`npm start`~~\n```bash\nsleep 45\n```\n\n## Docker Engine\nDocker Engine has 3 main components:\n\n1. Docker Daemon:\n   Manages Docker objects, volumes, images, containers, etc.\n2. REST API Interface:\n   Facilitates communication between the Docker Daemon and Docker CLI.\n3. Docker CLI:\n   A command-line interface to interact from third parties.\n\nNote that Docker CLI can be used from another system by specifying the command with the remote address of the Docker Daemon, like:\n```bash\ndocker -H=10.123.2.1:2375 run nginx\n```\n\nBy default, Docker does not specify any restriction on how much CPU or RAM a container can use. We can specify that using the following commands:\n```bash\ndocker run --cpus=.5 ubuntu  # use only 50% of CPU at max\ndocker run --memory=100m ubuntu  # use only 100 MB of memory at max\n```\n\n## Docker Storage\nDocker has a layered architecture, meaning it creates layers when executing commands in a Dockerfile:\n\nFor example:\n```Dockerfile\nFROM ubuntu\nRUN apt-get update \u0026\u0026 apt-get install python\nRUN pip install flask flask-mysql\nCOPY . /opt/source-code\nENTRYPOINT FLASK_APP=/opt/source-code/app.py flask run\n```\n\nWhen this Dockerfile runs with the command:\n```bash\ndocker build -t uzair/my-custom-app .\n```\n\nIt creates layers like this:\n- **Layer 1**: Base Ubuntu layer\n- **Layer 2**: Changes in apt packages\n- **Layer 3**: Changes in pip packages\n- **Layer 4**: Source code\n- **Layer 5**: Update ENTRYPOINT\n\nAll the above layers can also be called image layers because it creates an image from a Dockerfile.\n\nWhen an image is created, we need to run a command to run this image. To do that, we need to create a container for that image:\n```bash\ndocker run uzair/my-custom-app\n```\n\nIt creates another layer called the container layer:\n- **Layer 6**: Container layer\n\n**Note:** The container layer is read/write, but the image layer is read-only.\n\nWhen we wish to change the code of our given files, like `app.py`, the changes go to the container, and image files remain the same because there may be more than one container running from this image. This is called **Copy-on-write**.\n\nWhen we stop and destroy the container, all of our changes will be permanently removed from the container, and we cannot persist these changes for our running code. To overcome this problem, Docker introduces volumes.\n\nWe can create a volume by running the following command:\n```bash\ndocker volume create my-volume\n```\n\nThere are two types of volumes:\n- Volume mounting:\n  Using volumes that Docker creates for our containers to share space.\n- Bind mounting:\n  Using any folder or path from our system as shared space.\n\nTo run a Docker command with mounting, Docker introduces the `--mount` parameter, for example:\n```bash\ndocker run \\\n--mount type=bind,source=/data/mysql,target=/var/lib/mysql mysql\n```\n\nWho is responsible for creating and managing these mountings and volumes? Storage drivers handle this. There are many storage drivers based on the OS; Docker uses them accordingly:\n- AUFS\n- ZFS (Ubuntu OS by default)\n- BTRFS\n- Device Mapper\n- Overlay\n- Overlay2 (MacOS by default)\n\n## Networks\nThere are three networks created by default when you install Docker:\n1. Bridge (default network when running a container):\n   When we run a container, it uses the bridge network by default. This means all the containers connected to the bridge network can communicate with each other using local addresses.\n2. None:\n   When using none, it means our container is not connected to any network; it is a standalone container.\n   ```bash\n   docker run ubuntu --network=none\n   ```\n3. Host:\n   In the case of Host, a container can be connected to use resources that our host/app uses. This means when we run this container, it will connect to the host port and use that port to communicate outside the network.\n   Only one container can use the host network, as there is only one port connected to the host port.\n   ```bash\n   docker run ubuntu --network=host\n   ```\n\n### User-defined Networks\nCreate a network using the following command:\n```bash\ndocker network create \\\n  --driver bridge \\\n  --subnet 182.18.0.0/16 \\\n  custom-isolated-network\n```\n\nInspect Network:\nIn a container settings JSON, there is a property called NetworkSettings. In this node, you can find all the details about that container's network. To view the network settings, run the following command:\n```bash\ndocker inspect \u003ccontainer-name\u003e\n```\n\nTo view all the available networks in a system:\n```bash\ndocker network ls\n```\n\nTo inspect a network (e.g., gateway, subnet, etc.):\n```bash\ndocker network inspect \u003cnetwork-name\u003e\n```\n\nDocker has a built-in DNS server, so containers can reach each other by using names. Docker uses network-embedded DNS to get the IP address of the required container. (This prevents other network containers within a host from being accessed.)\n\n## Docker Registry\nA central repository for Docker images.\nStorage and distribution system for named Docker images, similar to npm, Crate, etc.\nWhen we write `image: nginx/nginx`, it searches on Docker Hub for that image and downloads it from Docker Hub (docker.io).\n\n### Own Private Registry\nTo create a private registry:\n```bash\ndocker run -d -p 5000:5000 --restart=always --name my-registry registry:2\n```\nNow, if we want to push some images to our registry server (e.g., nginx:latest):\n```bash\ndocker pull nginx:latest\ndocker image tag nginx:latest localhost:5000/nginx:latest\ndocker push localhost:5000/nginx:latest\n```\n\nYou can pull that image from this private registry using this command:\n```bash\ndocker pull localhost:5000/nginx\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuzair120%2Fdockerdoc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuzair120%2Fdockerdoc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuzair120%2Fdockerdoc/lists"}