├── Module07 └── README.md ├── .gitattributes ├── Module03 ├── img │ ├── readonly.png │ ├── view-new-file.png │ ├── write-newVolume.png │ ├── docker-volume-help.png │ ├── docker-volume-ls.png │ ├── docker-volume-mounted.png │ └── docker-volume-created-inspect.png └── README.md ├── Module05 ├── img │ ├── yaml-1.png │ ├── yaml-2.png │ ├── yaml-3.png │ ├── yaml-4.png │ ├── yaml-5.png │ ├── yaml-6.png │ ├── multistage-1.png │ ├── multistage-2.png │ ├── multistage-3.png │ └── dockerfile-intro.png └── README.md ├── Module02 ├── img │ ├── docker-run.jpg │ ├── docker-tag.png │ ├── docker-top.png │ ├── docker-attach.png │ ├── docker-commit.png │ ├── docker-create.png │ ├── docker-detach.png │ ├── docker-images.jpg │ ├── docker-login.png │ ├── docker-ps-a.jpg │ ├── docker-ps-aa.jpg │ ├── ubuntu-search.jpg │ ├── docker-push-denied.png │ ├── docker-create-start.png │ ├── docker-push-success.png │ └── docker-created-started.png └── README.md ├── Module06 ├── img │ ├── swarm-down.png │ ├── swarm-help.png │ ├── swarm-info.png │ ├── swarm-init.png │ ├── swarm-join.png │ ├── swarm-left.png │ ├── swarm-node.png │ ├── swarm-removed.png │ ├── DockerArchitecture.png │ ├── swarm-join-advance.png │ └── swarm-service-overview.png └── README.md ├── Module04 ├── img │ ├── docker-events.png │ ├── create-network.png │ ├── docker-network-ls.png │ ├── httpd-forward-port.png │ ├── httpd-working-test.png │ ├── docker-network-help.png │ ├── docker-network-inspect.png │ └── docker-network-create-help.png └── README.md ├── Module06 Continued ├── img │ ├── stack-1.png │ ├── overlay-1.png │ ├── overlay-2.png │ └── overlay-3.png └── README.md ├── LICENSE ├── README.md └── Module01 └── README.md /Module07/README.md: -------------------------------------------------------------------------------- 1 | # Module 06: Docker Security & Forensics -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Module03/img/readonly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module03/img/readonly.png -------------------------------------------------------------------------------- /Module05/img/yaml-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module05/img/yaml-1.png -------------------------------------------------------------------------------- /Module05/img/yaml-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module05/img/yaml-2.png -------------------------------------------------------------------------------- /Module05/img/yaml-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module05/img/yaml-3.png -------------------------------------------------------------------------------- /Module05/img/yaml-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module05/img/yaml-4.png -------------------------------------------------------------------------------- /Module05/img/yaml-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module05/img/yaml-5.png -------------------------------------------------------------------------------- /Module05/img/yaml-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module05/img/yaml-6.png -------------------------------------------------------------------------------- /Module02/img/docker-run.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module02/img/docker-run.jpg -------------------------------------------------------------------------------- /Module02/img/docker-tag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module02/img/docker-tag.png -------------------------------------------------------------------------------- /Module02/img/docker-top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module02/img/docker-top.png -------------------------------------------------------------------------------- /Module06/img/swarm-down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module06/img/swarm-down.png -------------------------------------------------------------------------------- /Module06/img/swarm-help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module06/img/swarm-help.png -------------------------------------------------------------------------------- /Module06/img/swarm-info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module06/img/swarm-info.png -------------------------------------------------------------------------------- /Module06/img/swarm-init.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module06/img/swarm-init.png -------------------------------------------------------------------------------- /Module06/img/swarm-join.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module06/img/swarm-join.png -------------------------------------------------------------------------------- /Module06/img/swarm-left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module06/img/swarm-left.png -------------------------------------------------------------------------------- /Module06/img/swarm-node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module06/img/swarm-node.png -------------------------------------------------------------------------------- /Module02/img/docker-attach.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module02/img/docker-attach.png -------------------------------------------------------------------------------- /Module02/img/docker-commit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module02/img/docker-commit.png -------------------------------------------------------------------------------- /Module02/img/docker-create.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module02/img/docker-create.png -------------------------------------------------------------------------------- /Module02/img/docker-detach.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module02/img/docker-detach.png -------------------------------------------------------------------------------- /Module02/img/docker-images.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module02/img/docker-images.jpg -------------------------------------------------------------------------------- /Module02/img/docker-login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module02/img/docker-login.png -------------------------------------------------------------------------------- /Module02/img/docker-ps-a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module02/img/docker-ps-a.jpg -------------------------------------------------------------------------------- /Module02/img/docker-ps-aa.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module02/img/docker-ps-aa.jpg -------------------------------------------------------------------------------- /Module02/img/ubuntu-search.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module02/img/ubuntu-search.jpg -------------------------------------------------------------------------------- /Module03/img/view-new-file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module03/img/view-new-file.png -------------------------------------------------------------------------------- /Module04/img/docker-events.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module04/img/docker-events.png -------------------------------------------------------------------------------- /Module05/img/multistage-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module05/img/multistage-1.png -------------------------------------------------------------------------------- /Module05/img/multistage-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module05/img/multistage-2.png -------------------------------------------------------------------------------- /Module05/img/multistage-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module05/img/multistage-3.png -------------------------------------------------------------------------------- /Module06/img/swarm-removed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module06/img/swarm-removed.png -------------------------------------------------------------------------------- /Module03/img/write-newVolume.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module03/img/write-newVolume.png -------------------------------------------------------------------------------- /Module04/img/create-network.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module04/img/create-network.png -------------------------------------------------------------------------------- /Module02/img/docker-push-denied.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module02/img/docker-push-denied.png -------------------------------------------------------------------------------- /Module03/img/docker-volume-help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module03/img/docker-volume-help.png -------------------------------------------------------------------------------- /Module03/img/docker-volume-ls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module03/img/docker-volume-ls.png -------------------------------------------------------------------------------- /Module04/img/docker-network-ls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module04/img/docker-network-ls.png -------------------------------------------------------------------------------- /Module04/img/httpd-forward-port.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module04/img/httpd-forward-port.png -------------------------------------------------------------------------------- /Module04/img/httpd-working-test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module04/img/httpd-working-test.png -------------------------------------------------------------------------------- /Module05/img/dockerfile-intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module05/img/dockerfile-intro.png -------------------------------------------------------------------------------- /Module06 Continued/img/stack-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module06 Continued/img/stack-1.png -------------------------------------------------------------------------------- /Module06/img/DockerArchitecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module06/img/DockerArchitecture.png -------------------------------------------------------------------------------- /Module06/img/swarm-join-advance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module06/img/swarm-join-advance.png -------------------------------------------------------------------------------- /Module02/img/docker-create-start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module02/img/docker-create-start.png -------------------------------------------------------------------------------- /Module02/img/docker-push-success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module02/img/docker-push-success.png -------------------------------------------------------------------------------- /Module04/img/docker-network-help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module04/img/docker-network-help.png -------------------------------------------------------------------------------- /Module06 Continued/img/overlay-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module06 Continued/img/overlay-1.png -------------------------------------------------------------------------------- /Module06 Continued/img/overlay-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module06 Continued/img/overlay-2.png -------------------------------------------------------------------------------- /Module06 Continued/img/overlay-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module06 Continued/img/overlay-3.png -------------------------------------------------------------------------------- /Module02/img/docker-created-started.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module02/img/docker-created-started.png -------------------------------------------------------------------------------- /Module03/img/docker-volume-mounted.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module03/img/docker-volume-mounted.png -------------------------------------------------------------------------------- /Module04/img/docker-network-inspect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module04/img/docker-network-inspect.png -------------------------------------------------------------------------------- /Module06/img/swarm-service-overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module06/img/swarm-service-overview.png -------------------------------------------------------------------------------- /Module04/img/docker-network-create-help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module04/img/docker-network-create-help.png -------------------------------------------------------------------------------- /Module03/img/docker-volume-created-inspect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaulagaisachin/learnDocker/HEAD/Module03/img/docker-volume-created-inspect.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Sachin Chaulagai 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Learn Docker :whale: 3 | 4 | Docker is the most amazing and life-changing technology ever invented (said no one who has ever spent hours trying to debug a Dockerfile). 5 | 6 | In reality, Docker is a tool that allows you to package applications and their dependencies into lightweight container images, which can then be run on any machine with a Docker runtime. It makes it easy to build, deploy, and run applications in a consistent and isolated environment, regardless of the underlying infrastructure. 7 | 8 | But don't let that simplicity fool you - Docker can be a real pain to work with at times, especially when you're trying to get a multi-container application up and running. Between trying to figure out the right combination of volumes, networks, and dependencies, you'll probably want to pull your hair out more than once. 9 | 10 | Despite its challenges, Docker is an extremely popular and widely-used tool that has revolutionized the way we deploy and run applications. So, if you're up for a bit of a challenge and want to spend hours debugging your Dockerfiles, go ahead and give it a try! 11 | 12 | 13 | ## Table of Content: 14 | 15 | | Modules | Description | 16 | | ----------- | ----------- | 17 | | [Module 01](https://github.com/chaulags/learnDocker/tree/main/Module01#module-01-docker-install--configure) | Docker Install & Configure :hammer_and_wrench: | 18 | | [Module 02](https://github.com/chaulags/learnDocker/tree/main/Module02#module-02-image-creation--management--registry) | Image Creation , Management & Registry :gear: | 19 | | [Module 03](https://github.com/chaulags/learnDocker/tree/main/Module03#module-03-docker-storage-and-volumes) | Docker Storage and Volumes :department_store: | 20 | | [Module 04](https://github.com/chaulags/learnDocker/tree/main/Module04#module-04-docker-networking) | Docker Networking :chains: | 21 | | [Module 05](https://github.com/chaulags/learnDocker/tree/main/Module05#module-05-docker-image-creation--compose) | Docker Image Creation & Compose :cyclone: | 22 | | [Module 06](https://github.com/chaulags/learnDocker/tree/main/Module06#module-06-container-orchestration-using-docker-swarm) | Container Orchestration :chains: :cloud: | 23 | | [Module 06 Continued](https://github.com/chaulags/learnDocker/tree/main/Module06%20Continued#docker-swarm-continued) | Container Orchestration Continued :chains: | 24 | | [Module 07](https://github.com/chaulags/learnDocker/tree/main/Module07#module-07-docker-security--forensics) | Docker Security & Forensics :bow_and_arrow: :shield: | 25 | 26 | ## Documentation 27 | 28 | [Docker Official Documentation](https://docs.docker.com/) 29 | 30 | 31 | ## Authors 32 | 33 | - [@chaulags](https://www.github.com/chaulags) 34 | 35 | -------------------------------------------------------------------------------- /Module03/README.md: -------------------------------------------------------------------------------- 1 | # Module 03: Docker Storage and Volumes 2 | * [Understanding the need for Volume service in Docker](https://github.com/chaulags/learnDocker/tree/main/Module03#understanding-the-need-for-volume-service-in-docker) 3 | * [Create and Manage volumes](https://github.com/chaulags/learnDocker/tree/main/Module03#create-and-manage-volumes) 4 | * [Start a container with a volume](https://github.com/chaulags/learnDocker/tree/main/Module03#start-a-container-with-a-volume) 5 | * [Populate data in a volume using a container](https://github.com/chaulags/learnDocker/tree/main/Module03#populate-data-in-a-volume-using-a-container) 6 | * [Use a read - only volume](https://github.com/chaulags/learnDocker/tree/main/Module03#use-a-read---only-volume) 7 | * [Understanding various Volume Plug-ins](https://github.com/chaulags/learnDocker/tree/main/Module03#understanding-various-volume-plug-ins) 8 | 9 | ## Understanding the need for Volume service in Docker 10 | * Docker volumes are file systems mounted on running containers to make sure that the data generated is preserved even after the docker container is stopped. 11 | * Its independent to the container and its lifecycle. 12 | * This helps to share required files from host system to container. 13 | * This storage implementation is also optimal for retrieving, storing, and transferring images across various environments. 14 | * Can be mapped to local storage. 15 | * Multiple container can use the same volume. 16 | 17 | ## Create and Manage volumes 18 | * We can use following commands to view volume information. 19 | * Try to explore more about volume using the following information: 20 | ``` 21 | sudo docker volume --help 22 | ``` 23 | ![docker-volume-help](img/docker-volume-help.png) 24 | 25 | ``` 26 | sudo docker volume ls 27 | ``` 28 | ![docker-volume-ls](img/docker-volume-ls.png) 29 | 30 | 31 | #### Create a volume & Inspect. 32 | * To create a volume, use following commands: 33 | ``` 34 | sudo docker volume create 35 | ``` 36 | * To view information about the volume just created, use: 37 | ``` 38 | sudo docker volume inspect 39 | ``` 40 | ![docker-volume-created-inspect](img/docker-volume-created-inspect.png) 41 | 42 | 43 | ## Start a container with a volume 44 | * *--mount* will help to mount the volume create. Make sure to give proper parameters. 45 | ``` 46 | sudo docker run -it --name --mount source=,target= 47 | ``` 48 | 49 | * We can also use different way to mount a docker volume. 50 | ``` 51 | sudo docker run -it -v : 52 | ``` 53 | ![docker-mount](img/docker-volume-mounted.png) 54 | 55 | * In a different scenerio, you can also directly load your host's directory in the container itself by using 56 | ``` 57 | sudo docker run -it -v : 58 | ``` 59 | 60 | ## Populate data in a volume using a container 61 | * You can create file such as following to create a persistent work. 62 | ![docker-write-file](img/write-newVolume.png) 63 | 64 | * To verify your files, inspect the volume and look at the files created. 65 | ![view-created-file](img/view-new-file.png) 66 | 67 | * Similarly, you can also configure web servers to send their logs here or application's persistent data that is to be stored. 68 | 69 | ## Use a read - only volume 70 | * Sometime you need the volume just to load configuration into the container. 71 | * You dont want docker container to change anything but just to read. 72 | * You can use following command or add parameter to make the mounted volume readonly. 73 | ``` 74 | sudo docker run -it --name --mount source=,target=,readonly 75 | ``` 76 | * Try Writing something inside it. 77 | 78 | * Even if you tried to change its permission, this is what you will get! 79 | ![readonly](img/readonly.png) 80 | 81 | ## Understanding various Volume Plug-ins 82 | * Docker Engine volume plugins enable Engine deployments to be integrated with external storage systems such as Amazon EBS, and enable data volumes to persist beyond the lifetime of a single Docker host. 83 | * That's something related to cloud so we will deal such tech later. 84 | 85 | **This is the End of Module 3** 86 | 87 | [>> **Module 4**](https://github.com/chaulags/learnDocker/tree/main/Module04#module-04-docker-networking) 88 | 89 | [ * * Go to Top * * ](https://github.com/chaulags/learnDocker/tree/main/Module03#module-03-docker-storage-and-volumes) 90 | 91 | 92 | -------------------------------------------------------------------------------- /Module06 Continued/README.md: -------------------------------------------------------------------------------- 1 | # Docker Swarm Continued (Deployment in Swarm) 2 | * Multiple Deployment at the same time. 3 | * In real world, there are multiple container with different services. 4 | * Frontend, backend, database, token generator, API requests & other. 5 | * This is where **Docker Stack Deploy** comes around. 6 | * Docker Stack Deploy uses YAML file with all the configuration to deploy everything at once. 7 | ![stack-1](img/stack-1.png) 8 | 9 | * Command used to deploy a Swarm Stack. 10 | ``` 11 | sudo dcoker stack deploy -c .yml 12 | ``` 13 | * Use *sudo docker ps* to view extra information. 14 | * There are no replucas in any other worker nodes. 15 | * As default replicas is 1. 16 | * Using following to view the number of replicas. 17 | ``` 18 | sudo docker service ls 19 | ``` 20 | 21 | 22 | ## Scaling 23 | * Scaling is the process of adding or removing compute, storage, and network services to meet the demands a workload makes for resources in order to maintain availability and performance as utilization increases. 24 | ![scaling](https://pimages.toolbox.com/wp-content/uploads/2021/11/29130051/Horizontal-vs.-VerticalScaling.jpg) 25 | * Since there are only 1 replica for a service. 26 | * We need to upscale it. 27 | * Following commands can be used to upscale or down your service as desired. 28 | 29 | ``` 30 | sudo docker service scale = 31 | ``` 32 | * View the replicas using. 33 | ``` 34 | sudo docker service ps 35 | ``` 36 | 37 | 38 | ## Rolling Updates 39 | * Updating an image in the service, while the service is running. 40 | * To reduce the downtime as less as possible. 41 | * Service Level agreement binds technical team to take such procedures. 42 | ``` 43 | sudo docker service create --name --replicas 3 44 | ``` 45 | ``` 46 | sudo docker service update --image 47 | ``` 48 | 49 | 50 | ## Draining Nodes 51 | * In earlier steps of the tutorial, all the nodes have been running with ACTIVE availability. 52 | * The swarm manager can assign tasks to any ACTIVE node, so up to now all nodes have been available to receive tasks. 53 | * Sometimes, such as planned maintenance times, you need to set a node to DRAIN availability. 54 | * DRAIN availability prevents a node from receiving new tasks from the swarm manager. 55 | * It also means the manager stops tasks running on the node and launches replica tasks on a node with ACTIVE availability. 56 | ``` 57 | sudo docker node update --availability drain 58 | ``` 59 | * All the loads handled by the drain node will be transfered to manager node. 60 | 61 | 62 | ## Connecting Service to a Network 63 | * The overlay network driver creates a distributed network among multiple Docker daemon hosts. 64 | * This network sits on top of (overlays) the host-specific networks, allowing containers connected to it (including swarm service containers) to communicate securely when encryption is enabled. 65 | 66 | ![overlay-1](img/overlay-1.png) 67 | 68 | ![overlay-2](img/overlay-2.png) 69 | 70 | ![overlay-3](img/overlay-3.png) 71 | 72 | 73 | * Let's create a overlay network driver first. 74 | ``` 75 | sudo docker network create --driver overlay my-overlay 76 | ``` 77 | * Overlay driver is created. Now use the network in services. 78 | ``` 79 | sudo docker service create --replicas 3 --network my-overlay --name testing nginx:latest 80 | ``` 81 | * Update the network connection to existing service 82 | ``` 83 | sudo docker service update --network-add mynewnetwork 84 | ``` 85 | * Remove the network 86 | ``` 87 | sudo docker service update --network-rm myoldnetwork 88 | ``` 89 | * View changes 90 | ``` 91 | sudo dcoker service inspect --pretty 92 | ``` 93 | 94 | 95 | ## Storage in Service 96 | * Adding volume to the service 97 | ``` 98 | sudo docker service create --mount src=,dst= --name myservice 99 | ``` 100 | * View changes 101 | ``` 102 | sudo dcoker service inspect --pretty 103 | ``` 104 | 105 | ## Replicated & Global 106 | **Replicated**: The tasks are replicated to a specified number using the ***--replicas*** flag and then each task is assigned to a node. 107 | ``` 108 | sudo docker service create --name --replicas 3 109 | ``` 110 | 111 | **Global**: This type of service runsone task on every node.Eg -Monitoring Agents, Antivirus Scanners. 112 | ``` 113 | sudo docker service create --name --mode global 114 | ``` 115 | 116 | ## Reserving Memory & CPU 117 | --reserve-memory 118 | --reserve-cpu 119 | -------------------------------------------------------------------------------- /Module05/README.md: -------------------------------------------------------------------------------- 1 | # Module 05: Docker Image Creation & Compose 2 | * [Introduction to DockerFile](https://github.com/chaulags/learnDocker/tree/main/Module05#introduction-to-dockerfile) 3 | * [Describe Dockerfile options](https://github.com/chaulags/learnDocker/tree/main/Module05#describe-dockerfile-options) 4 | * [Write Dockerfile to create Image](https://github.com/chaulags/learnDocker/tree/main/Module05#write-dockerfile-to-create-image) 5 | * [Multi-Stage Dockerfile](https://github.com/chaulags/learnDocker/tree/main/Module05#multi-stage-dockerfile) 6 | * [Docker Compose](https://github.com/chaulags/learnDocker/tree/main/Module05#introduction-to-docker-compose) 7 | * [Understanding docker-compose file](https://github.com/chaulags/learnDocker/tree/main/Module05#understanding-docker-compose-file) 8 | 9 | 10 | ## Introduction to DockerFile 11 | * A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. 12 | * Dockerfile is used for automation of work by specifying all step that we want on docker image. 13 | * Dockerfile is automated script of Docker images 14 | * Manual image creation will become complicated when you want to test same setup on different OS flavor 15 | * You have to create image for all flavor but by small changing in dockerfile you can create images for different flavor 16 | * It have simple syntax for image and do many change automatically that will take more time while doing manually. 17 | * Dockerfile have systematic step that can be understand by others easily and easy to know what exact configuration changed in base image. 18 | ![dockerfile-intro](img/dockerfile-intro.png) 19 | 20 | 21 | ## Describe Dockerfile options 22 | ![dockerfile-options](https://raw.githubusercontent.com/sangam14/dockercheatsheets/master/dockercheatsheet7.png) 23 | 24 | 25 | #### Example of a DockerFile 26 | ``` 27 | FROM ubuntu:latest 28 | RUN apt update 29 | RUN apt install –y apache2 30 | RUN apt install –y apache2-utils 31 | RUN apt clean 32 | EXPOSE 80 33 | CMD [“apache2ctl”, “-D”, “FOREGROUND”] 34 | ``` 35 | * Copy all the codes above and paste it into a file name DockerFile. 36 | * To build the docker image, go to the working directory and run following commands. 37 | 38 | ``` 39 | sudo docker build -t apacheimage:1.0 . 40 | ``` 41 | * View the created image using. 42 | ``` 43 | sudo docker images 44 | ``` 45 | * To run the built docker image. 46 | ``` 47 | sudo docker run --name myapache -d -p 80:80 apacheimage:1.0 48 | ``` 49 | 50 | 51 | ## Write Dockerfile to create Image 52 | 53 | **Exercise - Do it yourself** 54 | * Use nginx container. 55 | * Upgrade & Update the container system with all the required command. 56 | * Copy the configuration file from the host system to container. 57 | * Copy the content for the website from host to container and chnage ownership of the files. 58 | * Change the user and create a temp log files in tmp directory for the nginx to write its logs. 59 | 60 | 61 | ## Multi-Stage Dockerfile 62 | * Best way to reduce the size of your docker image. 63 | * What is happening here? 64 | 65 | ![multistage1](img/multistage-1.png) 66 | 67 | * Size of the image will approximately be like 700MB+ 68 | * Let's obseve another solution for the same problem. 69 | 70 | 71 | ![multistage1](img/multistage-2.png) 72 | * Size of the image will approximately be like 1GB+ 73 | * Can there be any optimal way to write a dockerfile. 74 | 75 | 76 | ![multistage1](img/multistage-3.png) 77 | * What's the difference in the last DockerFile. 78 | 79 | 80 | ## Introduction to Docker Compose 81 | * Docker Compose is a tool that was developed to help define and share multi-container applications. 82 | * With Compose, we can create a YAML file to define the services and with a single command, can spin everything up or tear it all down. 83 | ![docker-compose-explained](https://www.simplilearn.com/ice9/free_resources_article_thumb/docker-yaml.JPG) 84 | 85 | #### Benefits of Using Docker Compose: 86 | * **Single host deployment** - This means you can run everything on a single piece of hardware. 87 | * **Quick and easy configuration** - Due to YAML scripts. 88 | * **High productivity** - Docker Compose reduces the time it takes to perform tasks. 89 | * **Security** - All the containers are isolated from each other, reducing the threat landscape. 90 | 91 | 92 | #### YAML crash course 93 | * Yet Another Markup Language 94 | * Key Value pairs declare like this: 95 | ![yaml-1](img/yaml-1.png) 96 | * Arrays|List are declare like this: 97 | ![yaml-2](img/yaml-2.png) 98 | * Maps are defined like this: 99 | ![yaml-3](img/yaml-3.png) 100 | * YAML Spacing 101 | ![yaml-4](img/yaml-4.png) 102 | * Arrays with directories 103 | ![yaml-5](img/yaml-5.png) 104 | * Comments in YAMl 105 | ![yaml-6](img/yaml-6.png) 106 | 107 | 108 | ## Understanding docker-compose file 109 | ``` 110 | services: 111 | serviceName: 112 | build: ./pathToDockerFile 113 | volumes: 114 | - ./webApp:/usr/src/app 115 | ports: 116 | - hostPort:containerPort 117 | 118 | ``` 119 | 120 | -------------------------------------------------------------------------------- /Module01/README.md: -------------------------------------------------------------------------------- 1 | # Module 01: Docker Install & Configure 2 | * [Monolithic and Microservice Architecture](https://github.com/chaulags/learnDocker/tree/main/Module01#monolithic-and-microservice-architecture) 3 | * [Virtualization v/s Containerization](https://github.com/chaulags/learnDocker/tree/main/Module01#virtualization-vs-containerization) 4 | * [Introduction to Container & Docker](https://github.com/chaulags/learnDocker/tree/main/Module01#introduction-to-container--docker) 5 | * [Understanding the Docker components](https://github.com/chaulags/learnDocker/tree/main/Module01#understanding-the-docker-components--architecture) 6 | * [Docker Installation](https://github.com/chaulags/learnDocker/tree/main/Module01#docker-installation) 7 | 8 | 9 | ## Monolithic and Microservice Architecture 10 | 11 | 12 | | Monolithic Architecture | Microservice Architecture | 13 | | :-----------: | :-----------: | 14 | | Traditional model of software/application program which is self contained. | Modern way of software development that depends on modular component. | 15 | | Independent from any other application. | Dependent & modular but single module failure will not effect the whole application | 16 | | Singluar code base. | Different plugins could have different code base | 17 | | Update requires to change in the entire stack. | Easy update & speedy deployment | 18 | | Time Consuming. | Much more fast & efficient. | 19 | | Difficult to pin point the problems for large problem. | Easy debugging & code management. | 20 | 21 | 22 | ![Differences between Monolithic and Microservice](https://miro.medium.com/max/1000/1*b5vneT_J4-dKejbYH4o5qg.png) 23 | ![Monolithic and Microservice](https://wac-cdn.atlassian.com/dam/jcr:b2be0d53-f4b2-46d8-9a34-993048cc6225/Monolith%20Vs%20Microservice%20image.png?cdnVersion=549) 24 | 25 | 26 | ## Virtualization v/s Containerization 27 | 28 | | Virtualization | Containerization | 29 | | ----------- | ----------- | 30 | | Partitioning a physical server into multiple virtual servers. | Bundling the application code along with the libraries, configuration files, and dependencies required for the application to run cross-platform. | 31 | | Hypervisor Layer performs all the task. | Docker Daemon/Container Engine Layer performs all the task | 32 | | Hypervisor creates an abstract layer on the computer hardware, handles resource allocation, and monitors the virtual machines. | Piece of software that accepts user requests, including command line options, pulls images, and from the end user's perspective runs the container. | 33 | | Deploys an actual virtual server on top of hardware resouces. | Creates an environment for an application to run. | 34 | | Example: VMWare, VirtualBox | Example: Docker, LXD, Podman | 35 | 36 | 37 | 38 | ![Virtualization versus Containerization](https://images.contentstack.io/v3/assets/blt300387d93dabf50e/bltb6200bc085503718/5e1f209a63d1b6503160c6d5/containers-vs-virtual-machines.jpg) 39 | 40 | ## Introduction to Container & Docker 41 | 42 | Container: 43 | * Standard unit of software that packages up code and all its dependencies. 44 | * Runs quickly and reliably from one computing environment to another. 45 | * Lightweight, standalone, executable package of software that includes everything needed to run an application 46 | * Code, runtime, system tools, system libraries and settings. 47 | 48 | Docker: 49 | * Set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. 50 | * Program writtern in Go. 51 | * Containerd is the underlying technology that is a part of docker engine. 52 | 53 | 54 | ## Understanding the Docker components & Architecture 55 | Client Side 56 | * Docker CLI: Command line interface that is allowed to issue command to docker daemon for various task. 57 | * Remote API: RESTFul API accessed by an HTTP client such as 58 | 59 | Host Side 60 | * Docker Daemon: Also known as dockerd, listens for Docker API requests/CLI commands and manages Docker objects such as images, containers, networks, and volumes. 61 | * Images: Template file that is the foundation of a docker container. 62 | * Containers: Running version of a docker images. 63 | 64 | Docker Registry: Storage and distribution system for named Docker images. 65 | * Docker Hub 66 | * AWS Container Registry 67 | * Azure Container Registry 68 | 69 | ![Docker Architecture](https://docs.docker.com/engine/images/architecture.svg) 70 | 71 | ## Docker Installation 72 | 73 | Ubuntu/Debian Linux 74 | ``` 75 | sudo apt update && sudo apt upgrade 76 | sudo apt install docker.io docker-compose 77 | ``` 78 | Wait for the Stuff to get loaded 79 | \ 80 | ![Loading](https://media3.giphy.com/media/1iNIkQBAwEkUuTpikf/giphy.gif?cid=ecf05e471xtdgy62d1gagagkvlqddvnyqpnadv7mirrymn55&rid=giphy.gif&ct=g) 81 | \ 82 | **This is the End of Module 1** 83 | [>> **Module 2**](https://github.com/chaulags/learnDocker/tree/main/Module02#module-02-image-creation--management--registry) 84 | [ * * Go to Top * * ](https://github.com/chaulags/learnDocker/tree/main/Module01#module-01-docker-install--configure) 85 | -------------------------------------------------------------------------------- /Module06/README.md: -------------------------------------------------------------------------------- 1 | # Module 06: Container Orchestration using Docker Swarm 2 | * Container Orchestration 3 | * Docker Swarm Introduction 4 | * Docker Swarm Architecture 5 | * Docker Swarm and distribution strategies 6 | 13 | 14 | ## Container Orchestration 15 | * Container Orchestration is the process of delpying and maintainig large number of containers & services for the application to run as intended. 16 | * Automation of much of the operational effort required to run containerized workloads and services. 17 | * Manage a container's lifecycle, including provisioning, deployment, scaling (up and down), networking, load balancing and more. 18 | * Why Orchestration? 19 | * **Configuration and scheduling** 20 | * **Provisioning and deployment** 21 | * **Health monitoring** 22 | * **Resource allocation** 23 | * **Redundancy and availability** 24 | * **Updates and upgrades** 25 | * **Scaling or removing containers to balance workloads across the infrastructure** 26 | * **Moving containers between hosts** 27 | * **Load balancing and traffic routing** 28 | * **Securing container interactions** 29 | ![benefit](https://www.splunk.com/content/dam/splunk2/images/data-insider/container-orchestration/benefits-of-container-orchestration.jpg) 30 | 31 | * Container Orchestration Tools 32 | * Docker Swarm 33 | * Kubernetes 34 | * Mesos Marathon 35 | * Nomad 36 | * Amazon EKS 37 | * Azure Kubernetes Service 38 | 39 | ![lifecycle](https://k21academy.com/wp-content/uploads/2020/11/458769_1_En_14_Fig2_HTML-1.png) 40 | 41 | 42 | ## Docker Swarm Introduction 43 | * Docker Swarm is another popular open source container orchestration platform. 44 | * The cluster management and orchestration features embedded in the Docker Engine are built using swarmkit. 45 | * [Swarmkit](https://github.com/moby/swarmkit) is a separate project which implements Docker’s orchestration layer and is used directly within Docker. 46 | 47 | ## Docker Swarm Architecture 48 | 49 | ![architecture](img/DockerArchitecture.png) 50 | 51 | * **Services & Tasks**: 52 | * A service is the definition of the tasks to execute on the manager or worker nodes. 53 | * It is the central structure of the swarm system and the primary root of user interaction with the swarm. 54 | * For global services, the swarm runs one task for the service on every available node in the cluster. 55 | * **Task** carries a Docker container and the commands to run inside the container. It is the atomic scheduling unit of swarm. 56 | * Manager nodes assign tasks to worker nodes according to the number of replicas set in the service scale. 57 | 58 | 59 | * **Nodes**: A node is an instance of the Docker engine participating in the swarm. 60 | * **Manager Nodes**: 61 | * To maintain the cluster state. 62 | * Allocating IP addresses to tasks. 63 | * Accepting commands and creating service objects. 64 | * Assigning tasks to nodes. 65 | * Scheduling of Services. 66 | * Serving Swarm mode HTTP API endpoints. 67 | * Instructing a worker to run a task. 68 | * **Worker Nodes** 69 | * A manager node can exist without a worker node 70 | * Worker cannot exist without a manager. 71 | * Manager node assigns tasks to worker nodes. 72 | 73 | 74 | ## Docker Swarm Tutorials 75 | This part mostly contains the working of docker swarm and its deployment features. 76 | 77 | #### Initialize Docker Swarm 78 | * Following command will help you understand sub-feature of the docker-swarm. 79 | ``` 80 | sudo docker swarm help 81 | ``` 82 | ![swarm-help](img/swarm-help.png) 83 | 84 | * To initialize the docker swarm: 85 | ``` 86 | sudo docker swarm init --advertise-addr 87 | ``` 88 | ![swarm-init](img/swarm-init.png) 89 | 90 | * The above system is now the manager for the docker swarm cluster. 91 | * We can also see the instruction to add more worker to this swarm cluster. 92 | ![swarm-join](img/swarm-join.png) 93 | 94 | * To view more info about the docker-swarm: 95 | ``` 96 | sudo docker info ;; Go to Swarm Section 97 | ``` 98 | ![swarm-info](img/swarm-info.png) 99 | 100 | #### Manage Nodes in Docker Swarm Cluster 101 | * To view all the nodes: 102 | ``` 103 | sudo docker node ls 104 | ``` 105 | ![swarm-node](img/swarm-node.png) 106 | 107 | * How worker node leave a docker swarm. 108 | ``` 109 | sudo docker swarm leave --force 110 | ``` 111 | ![swarm-left](img/swarm-left.png) 112 | 113 | ![swarm-down](img/swarm-down.png) 114 | 115 | * Remove the node from docker swarm cluster's manager. 116 | ``` 117 | sudo docker node rm 118 | ``` 119 | ![swarm-removed](img/swarm-removed.png) 120 | 121 | * If you want to view the token to add a worker to the cluster, 122 | ``` 123 | sudo docker swarm join-token worker 124 | ``` 125 | * If you want to add a node as **MANAGER**n the token to add a node to the cluster, 126 | ``` 127 | sudo docker swarm join-token manager 128 | ``` 129 | ![swarm-join-advance](img/swarm-join-advance.png) 130 | 131 | #### Docker Service Management 132 | * Service is used to deploy an application image. 133 | * Service will define how your task is going to be executed. 134 | * For example service defines the replicas of the docker container to load balance the request for all the users & customers. 135 | * Replicas are mostly deployed in different worker nodes so that even if any worker shuts down, another instance in another worker will respond to the request. 136 | * Service might be slow, but availability of the service will not stop. 137 | * **REDUNDANCY** 138 | 139 | ![swarm-service-overview](img/swarm-service-overview.png) 140 | 141 | * To create a docker service: 142 | ``` 143 | sudo docker service create --replicas -p 144 | ``` 145 | * View services in all the nodes: 146 | ``` 147 | sudo docker service ls 148 | ``` 149 | ``` 150 | sudo docker service ps 151 | ``` 152 | * Let's try and remove any replicas. 153 | ``` 154 | sudo docker rm -f 155 | ``` 156 | * Wait for ittttt. 157 | * Check using following commands. 158 | ``` 159 | sudo docker ps 160 | ``` 161 | * Delete a Service 162 | ``` 163 | sudo docker rm 164 | ``` 165 | * Extra information of a Service 166 | ``` 167 | sudo docker service inspect --pretty 168 | ``` 169 | * 170 | -------------------------------------------------------------------------------- /Module04/README.md: -------------------------------------------------------------------------------- 1 | # Module 04: Docker Networking 2 | * [Accessing containers](https://github.com/chaulags/learnDocker/tree/main/Module04#accessing-containers) 3 | * [Exposing container ports](https://github.com/chaulags/learnDocker/tree/main/Module04#exposing-container-ports) 4 | * [Docker Networking](https://github.com/chaulags/learnDocker/tree/main/Module04#docker-networking) 5 | * [Linking containers](https://github.com/chaulags/learnDocker/tree/main/Module04#linking-containers) 6 | * [Naming Our Containers](https://github.com/chaulags/learnDocker/tree/main/Module04#naming-our-containers) 7 | * [Configure Docker to use external DNS](https://github.com/chaulags/learnDocker/tree/main/Module04#configure-docker-to-use-external-dns) 8 | * [Docker Events](https://github.com/chaulags/learnDocker/tree/main/Module04#docker-events) 9 | 10 | ## Accessing containers 11 | * There are different ways to connect to a docker container. 12 | * Some of them are listed below. 13 | ``` 14 | sudo docker attach 15 | ``` 16 | ``` 17 | sudo docker exec -it 18 | ``` 19 | * However, these techinques are not limited to above mentioned techniques. 20 | * We can also connect to varios container through network. 21 | * So, first of all, we'll discuss about docker containers. 22 | 23 | ## Exposing container ports 24 | * There are many cases where you need to expose various services. 25 | * Port are required to make the service available for the consumers. 26 | * Exposing ports will help to forward port from docker container to host network adapter. 27 | * Following commands can be used to forward | Expose port 28 | - -p hostPort>:containerPort:: used to forward certain port from container to host 29 | - -P :: Use to forward all the port from container to host. 30 | ``` 31 | sudo docker run -it -p 80:80 32 | ``` 33 | ``` 34 | sudo docker run -dit --name my-running-app -p 8080:80 httpd:latest 35 | ``` 36 | ![httpd-forward-port](img/httpd-forward-port.png) 37 | 38 | ![httpd-works](img/httpd-working-test.png) 39 | 40 | * Now the service is available to the host's port. 41 | * Same technique can be used to forward other service such as SSH. 42 | 43 | ## Docker Networking 44 | * One of the reasons Docker containers and services are so powerful is that you can connect them together, or connect them to non-Docker workloads. 45 | * Docker networking allows you to attach a container to as many networks as you like. 46 | * Docker networking enables a user to link a Docker container to as many networks as he/she requires. 47 | * Docker Networks are used to provide complete isolation for Docker containers. 48 | 49 | 50 | ## Linking containers 51 | * Docker supports networking for its containers via network drivers. 52 | * These drivers have several network drivers. 53 | 54 | | Network Type | Description | 55 | |---|---| 56 | | Bridge | The default network driver. If you don’t specify a driver, this is the type of network you are creating. Bridge networks are usually used when your applications run in standalone containers that need to communicate | 57 | | Host | For standalone containers, remove network isolation between the container and the Docker host, and use the host’s networking directly. | 58 | | None | For this container, disable all networking. Usually used in conjunction with a custom network driver. None is not available for swarm services. | 59 | | Overlay | Overlay networks connect multiple Docker daemons together and enable swarm services to communicate with each other. You can also use overlay networks to facilitate communication between a swarm service and a standalone container, or between two standalone containers on different Docker daemons. This strategy removes the need to do OS-level routing between these containers. | 60 | | MacVlan | Macvlan networks allow you to assign a MAC address to a container, making it appear as a physical device on your network. | 61 | | IPVlan | IPvlan networks give users total control over both IPv4 and IPv6 addressing. | 62 | 63 | 64 | #### Docker Network Connection 65 | ``` 66 | sudo docker network --help 67 | ``` 68 | ![docker-network](img/docker-network-help.png) 69 | 70 | ``` 71 | sudo docker network ls 72 | ``` 73 | ![docker-network-ls](img/docker-network-ls.png) 74 | 75 | ``` 76 | sudo docker network inspect 77 | ``` 78 | ![docker-inspect](img/docker-network-inspect.png) 79 | 80 | #### Create Different Network 81 | ``` 82 | sudo docker network create <--help> 83 | ``` 84 | ![docker-create-network-help](img/docker-network-create-help.png) 85 | 86 | ``` 87 | sudo docker network create -d 88 | ``` 89 | ![create-network](img/create-network.png) 90 | 91 | #### Change Network Adapters 92 | ``` 93 | sudo docker run -it --network 94 | ``` 95 | * To see what network(s) your container is on: 96 | ``` 97 | sudo docker inspect -f "{{json .NetworkSettings.Networks }}" 98 | ``` 99 | * To disconnect your container from the first network 100 | ``` 101 | docker network disconnect 102 | ``` 103 | * Then to reconnect it to another network 104 | ``` 105 | sudo docker network connect 106 | ``` 107 | * To check if two containers (or more) are on a network together 108 | ``` 109 | sudo docker network inspect -f "{{json .Containers }}" 110 | ``` 111 | 112 | ## Naming Our Containers 113 | ``` 114 | sudo docker run -it --hostname web ubuntu:latest 115 | ``` 116 | 117 | ## Configure Docker to use external DNS 118 | * There are two ways to change the docker DNS setting. 119 | * By adding another parameter while running a container 120 | - --dns DNSServerAddress 121 | ``` 122 | sudo docker run --dns 123 | ``` 124 | * Changing the default DNS address for the whole docker architecture. 125 | ``` 126 | sudo vim /etc/docker/daemon.json 127 | ``` 128 | * Add following: 129 | ``` 130 | { 131 | "dns": ["8.8.8.8"] 132 | } 133 | ``` 134 | * Also, restart your docker daemon. 135 | ``` 136 | sudo systemctl restart docker 137 | ``` 138 | ## Docker Events 139 | * Use *docker events* to get real-time events from the server. 140 | * These events differ per Docker object type. 141 | * Different event types have different scopes. 142 | * Container 143 | * Volume 144 | * Network 145 | * Images 146 | * Daemon 147 | * Service 148 | * Secrets 149 | * Config 150 | * Go to this [link](https://docs.docker.com/engine/reference/commandline/events/) for further information. 151 | * You can use docker event by 152 | ``` 153 | sudo docker events 154 | ``` 155 | * Now all the activity will be reported through the output. 156 | * You can also use linux redirections to store all these outputs. 157 | 158 | ![docker-events](img/docker-events.png) 159 | 160 | 161 | [>> **Module 5**](https://github.com/chaulags/learnDocker/tree/main/Module05#module-05-docker-image-creation--compose) 162 | 163 | [* * * Go To Top * * * ](https://github.com/chaulags/learnDocker/tree/main/Module04#module-04-docker-networking) 164 | -------------------------------------------------------------------------------- /Module02/README.md: -------------------------------------------------------------------------------- 1 | # Module 02: Image Creation , Management & Registry 2 | * [Docker Registry](https://github.com/chaulags/learnDocker/tree/main/Module02#docker-registry) 3 | * [Docker Images & Layers](https://github.com/chaulags/learnDocker/tree/main/Module02#docker-images--layers) 4 | * [Working with Containers](https://github.com/chaulags/learnDocker/tree/main/Module02#working-with-containers) 5 | * [Process in Containers](https://github.com/chaulags/learnDocker/tree/main/Module02#process-in-containers) 6 | * [Docker Lifecycles](https://github.com/chaulags/learnDocker/tree/main/Module02#docker-lifecycles) 7 | * [Docker Commit & Push](https://github.com/chaulags/learnDocker/tree/main/Module02#docker-commit--push) 8 | 9 | ## Docker Registry 10 | * Let's start with simple docker image. 11 | * Docker Hub will be used to fetch the docker images from the docker registry. 12 | * Go and create and account in [Docker Hub](https://hub.docker.com/) so that it will help you help you in later chapters. 13 | 14 | ``` 15 | https://hub.docker.com/ 16 | ``` 17 | 18 | ![DockerHub Image](https://static.packt-cdn.com/products/9781789137231/graphics/assets/01327d92-d3d2-4354-98bb-2a443adad38d.png) 19 | 20 | 21 | ## Docker Images & Layers 22 | * Search "Ubuntu" in docker hub to find the base template of the ubuntu OS. 23 | * You can see offical docker image for Ubuntu. 24 | ![DockerHub](img/ubuntu-search.jpg) 25 | * Use following commands to download/pull the image to your own local system. 26 | ``` 27 | docker pull ubuntu 28 | ``` 29 | * If you are having any error such as permission denied or similar, use: 30 | ``` 31 | sudo docker pull ubuntu 32 | ``` 33 | \ 34 | ![Downloading](https://media3.giphy.com/media/3o7WTAkv7Ze17SWMOQ/giphy.gif?cid=790b76115d7878163a2bd03d2a72099f218f17e42b0be33e&rid=giphy.gif&ct=g) 35 | 36 | * Wait for some seconds or minutes, depending upon your internet speed. 37 | * After the pull operation has been completed, use following commands to view your docker images in you local system. 38 | ``` 39 | docker images 40 | ``` 41 | \ 42 | ![Docker Images](img/docker-images.jpg) 43 | 44 | * To run the image, use: 45 | ``` 46 | docker run -i -t ubuntu:latest 47 | ``` 48 | * The above command's options are described as follows: 49 | * -i = Interactive session with the container that is to be executed. 50 | * -t = To make sure the session is interactive, a terminal is required. Hence. 51 | * ubuntu/ubuntu:latest = imageName:versionNumber 52 | \ 53 | ![docker-run](img/docker-run.jpg) 54 | 55 | * You can now interact with the running docker container through a terminal. 56 | 57 | 58 | ## Working with Containers 59 | * As you already have opened an interactive session by running a docker cotainer. 60 | * Wait a second before doing anything. Let's understand whats happenning here. 61 | * Docker Image is just a template for a container. Container is a executed version of the template environment itself. 62 | \ 63 | ![Docker Image & Container](https://davetang.github.io/reproducible_bioinformatics/assets/docker_image.png) 64 | * We can also view the information about container and its state, the following commands can be used. 65 | ``` 66 | docker ps -a 67 | ``` 68 | * -a = Show all containers (default shows just running) 69 | \ 70 | ![docker-ps-a](img/docker-ps-a.jpg) 71 | 72 | * Remember the information you have here. You'll be coming here a lot. 73 | * You have a terminal access to the docker container running a Ubuntu. 74 | * Use it for a while, see if you can find any difference. 75 | \ 76 | ![Waiting Meme](https://c.tenor.com/ycKJas-YT0UAAAAM/im-waiting-aki-and-paw-paw.gif) 77 | 78 | * There are various information about the container: 79 | * Container ID = Randomly generated ID to specify the running instance. 80 | * Image = The image used to create the container. 81 | * Command = The command executed while running the container(for ubuntu "bash" was executed) 82 | * Created = Time it has been created for. 83 | * Status = Running, exited. 84 | * Port = Any exposed ports 85 | * Name = Randomly generated name, these names can be used instead of container ID to execute stuffs. --name option can be used to give your own name for the container. 86 | * Now Exit the terminal. 87 | * Use the command that displays the [information about container and its state](https://github.com/chaulags/learnDocker/tree/main/Module02#working-with-containers). 88 | * What are the changes you can see ? 89 | \ 90 | ![Use your power meme](https://c.tenor.com/lTPOYFTdUKgAAAAC/you-ready-to-use-your-power-for-good-chris-cantada.gif) 91 | 92 | * Note down the changes you see. 93 | \ 94 | ![docker-stop](img/docker-ps-aa.jpg) 95 | 96 | 97 | 98 | ## Process in Containers 99 | * You can also run a container without attaching to it. 100 | ``` 101 | docker run -it -d ubuntu:latest 102 | ``` 103 | \ 104 | ![docker-detach](img/docker-detach.png) 105 | * View the information about running container 106 | * You can also attach yourself to docker container using: 107 | ``` 108 | docker attach 109 | ``` 110 | \ 111 | ![docker-attach](img/docker-attach.png) 112 | 113 | * You can also using following key combination for detaching yourself from a container: 114 | ``` 115 | CTRL + Q 116 | ``` 117 | * You can also view running processess without attaching to a docker container. 118 | ``` 119 | docker top 120 | ``` 121 | \ 122 | ![docker-top](img/docker-top.png) 123 | 124 | NOTE: do start ssh service in you container the view similar output as above. 125 | 126 | ## Docker Lifecycles 127 | * Docker container can also be just created without running it. 128 | ``` 129 | sudo docker container create -i -t --name myUbuntu ubuntu:latest 130 | ``` 131 | \ 132 | ![docker-create](img/docker-create.png) 133 | 134 | * Now the created docker container can be started using following commands: 135 | ``` 136 | sudo docker container start --attach -i myUbuntu 137 | ``` 138 | \ 139 | ![docker-create-start](img/docker-create-start.png) 140 | \ 141 | * Docker status can be checked 142 | ![docker-started](img/docker-created-started.png) 143 | 144 | * From this illustration , we can undertand that above commands are equivalent to: 145 | ``` 146 | sudo docker run -it --name myUbuntu ubuntu:latest 147 | ``` 148 | 149 | * Following are the Docker lifecycle stages: 150 | ![docker-lifecycle](https://k21academy.com/wp-content/uploads/2020/10/Capture-5.png) 151 | 152 | 153 | ## Docker Commit & Push 154 | * Docker container are just an instance of a docker images. 155 | * If the docker container are deleted, any changes will be deleted with it. 156 | * So, if a docker image is to be saved, we can use docker commit. 157 | * Docker commit will create your container's instance as an image. 158 | * So next time you start this new image, it will have everything you want. 159 | 160 | ``` 161 | docker commit 162 | ``` 163 | ![docker-commit](img/docker-commit.png) 164 | 165 | * Congratulation on you first commit. 166 | * This images of yours can also be uploaded to DockerHub, but first you need to login. 167 | ``` 168 | docker login 169 | ``` 170 | ![docker-login](img/docker-login.png) 171 | 172 | * Now use following commands to push your image to DockerHub 173 | 174 | ``` 175 | docker push 176 | ``` 177 | But, 178 | ![but-meme](https://c.tenor.com/mv8WDfaaqZkAAAAC/but-nevermind-meme.gif) 179 | 180 | * You get error, something like this: 181 | ![docker-push-error](img/docker-push-denied.png) 182 | 183 | * That's because you also need to specify your repository. 184 | * You can do that using docker tag. 185 | 186 | ``` 187 | docker tag 188 | ``` 189 | ![docker-tag](img/docker-tag.png) 190 | 191 | * Now, Let's Push again 192 | ![docker-push-success](img/docker-push-success.png) 193 | 194 | **This is the End of Module 2** 195 | 196 | [>> **Module 3**](https://github.com/chaulags/learnDocker/tree/main/Module03#module-03-docker-storage-and-volumes) 197 | 198 | [* * * Go To Top * * * ](https://github.com/chaulags/learnDocker/tree/main/Module02#module-02-image-creation--management--registry) 199 | 200 | 201 | --------------------------------------------------------------------------------