├── .gitignore ├── DockerCompose └── docker-compose.yml ├── Projects with Docker ├── first project │ ├── Dockerfile │ ├── index.py │ └── requirements.txt └── second project │ ├── .gitignore │ ├── Dockerfile │ ├── index.js │ ├── package-lock.json │ └── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .next/ 3 | node_modules/ 4 | yarn-error.log 5 | .pnpm-debug.log 6 | dist/ 7 | */**/.turbo 8 | # Theme styles 9 | packages/nextra-theme-*/style.css 10 | 11 | # Stork related 12 | */**/public/*.st 13 | */**/public/*.toml 14 | 15 | .vercel 16 | .idea/ 17 | 18 | # Logs 19 | logs 20 | .log 21 | npm-debug.log 22 | yarn-debug.log* 23 | yarn-error.log* 24 | lerna-debug.log* 25 | .pnpm-debug.log* 26 | 27 | # Diagnostic reports (https://nodejs.org/api/report.html) 28 | report.[0-9].[0-9].[0-9].[0-9].json 29 | 30 | # Runtime data 31 | pids 32 | *.pid 33 | *.seed 34 | *.pid.lock 35 | 36 | # Directory for instrumented libs generated by jscoverage/JSCover 37 | lib-cov 38 | 39 | # Coverage directory used by tools like istanbul 40 | coverage 41 | *.lcov 42 | 43 | # nyc test coverage 44 | .nyc_output 45 | 46 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 47 | .grunt 48 | 49 | # Bower dependency directory (https://bower.io/) 50 | bower_components 51 | 52 | # node-waf configuration 53 | .lock-wscript 54 | 55 | # Compiled binary addons (https://nodejs.org/api/addons.html) 56 | build/Release 57 | 58 | # Dependency directories 59 | node_modules/ 60 | jspm_packages/ 61 | 62 | # Snowpack dependency directory (https://snowpack.dev/) 63 | web_modules/ 64 | 65 | # TypeScript cache 66 | *.tsbuildinfo 67 | 68 | # Optional npm cache directory 69 | .npm 70 | 71 | # Optional eslint cache 72 | .eslintcache 73 | 74 | # Optional stylelint cache 75 | .stylelintcache 76 | 77 | # Microbundle cache 78 | .rpt2_cache/ 79 | .rts2_cache_cjs/ 80 | .rts2_cache_es/ 81 | .rts2_cache_umd/ 82 | 83 | # Optional REPL history 84 | .node_repl_history 85 | 86 | # Output of 'npm pack' 87 | *.tgz 88 | 89 | # Yarn Integrity file 90 | .yarn-integrity 91 | 92 | # dotenv environment variable files 93 | .env 94 | .env.development.local 95 | .env.test.local 96 | .env.production.local 97 | .env.local 98 | 99 | # parcel-bundler cache (https://parceljs.org/) 100 | .cache 101 | .parcel-cache 102 | 103 | # Next.js build output 104 | .next 105 | out 106 | 107 | # Nuxt.js build / generate output 108 | .nuxt 109 | dist 110 | 111 | # Gatsby files 112 | .cache/ 113 | # Comment in t 114 | -------------------------------------------------------------------------------- /DockerCompose/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | mongodb: 4 | image: mongo 5 | container_name: mongodb 6 | ports: 7 | - 27017:27017 8 | environment: 9 | - MONGO_INITDB_ROOT_USERNAME=admin 10 | - MONGO_INITDB_ROOT_PASSWORD=password 11 | volumes: 12 | - mongodb_data:/data/db 13 | mongo-express: 14 | image: mongo-express 15 | restart: always 16 | container_name: mongo-express 17 | ports: 18 | - 8081:8081 19 | environment: 20 | - ME_CONFIG_MONGODB_ADMINUSERNAME=admin 21 | - ME_CONFIG_MONGODB_ADMINPASSWORD=password 22 | - ME_CONFIG_MONGODB_SERVER=mongodb 23 | volumes: 24 | mongodb_data: 25 | driver: local 26 | -------------------------------------------------------------------------------- /Projects with Docker/first project/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3-alpine3.15 2 | WORKDIR /app 3 | COPY . /app 4 | RUN pip install -r requirements.txt 5 | EXPOSE 5000 6 | CMD python ./index.py -------------------------------------------------------------------------------- /Projects with Docker/first project/index.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | helloworld = Flask(__name__) 3 | 4 | @helloworld.route("/") 5 | def run(): 6 | return "{ \"message\": \"Hey there I am Subham\" }" 7 | 8 | if __name__ == "__main__": 9 | helloworld.run(host="0.0.0.0", port=int("5000"), debug=True) -------------------------------------------------------------------------------- /Projects with Docker/first project/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==2.2.3 -------------------------------------------------------------------------------- /Projects with Docker/second project/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .next/ 3 | node_modules/ 4 | yarn-error.log 5 | .pnpm-debug.log 6 | dist/ 7 | */**/.turbo 8 | # Theme styles 9 | packages/nextra-theme-*/style.css 10 | 11 | # Stork related 12 | */**/public/*.st 13 | */**/public/*.toml 14 | 15 | .vercel 16 | .idea/ 17 | 18 | # Logs 19 | logs 20 | .log 21 | npm-debug.log 22 | yarn-debug.log* 23 | yarn-error.log* 24 | lerna-debug.log* 25 | .pnpm-debug.log* 26 | 27 | # Diagnostic reports (https://nodejs.org/api/report.html) 28 | report.[0-9].[0-9].[0-9].[0-9].json 29 | 30 | # Runtime data 31 | pids 32 | *.pid 33 | *.seed 34 | *.pid.lock 35 | 36 | # Directory for instrumented libs generated by jscoverage/JSCover 37 | lib-cov 38 | 39 | # Coverage directory used by tools like istanbul 40 | coverage 41 | *.lcov 42 | 43 | # nyc test coverage 44 | .nyc_output 45 | 46 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 47 | .grunt 48 | 49 | # Bower dependency directory (https://bower.io/) 50 | bower_components 51 | 52 | # node-waf configuration 53 | .lock-wscript 54 | 55 | # Compiled binary addons (https://nodejs.org/api/addons.html) 56 | build/Release 57 | 58 | # Dependency directories 59 | node_modules/ 60 | jspm_packages/ 61 | 62 | # Snowpack dependency directory (https://snowpack.dev/) 63 | web_modules/ 64 | 65 | # TypeScript cache 66 | *.tsbuildinfo 67 | 68 | # Optional npm cache directory 69 | .npm 70 | 71 | # Optional eslint cache 72 | .eslintcache 73 | 74 | # Optional stylelint cache 75 | .stylelintcache 76 | 77 | # Microbundle cache 78 | .rpt2_cache/ 79 | .rts2_cache_cjs/ 80 | .rts2_cache_es/ 81 | .rts2_cache_umd/ 82 | 83 | # Optional REPL history 84 | .node_repl_history 85 | 86 | # Output of 'npm pack' 87 | *.tgz 88 | 89 | # Yarn Integrity file 90 | .yarn-integrity 91 | 92 | # dotenv environment variable files 93 | .env 94 | .env.development.local 95 | .env.test.local 96 | .env.production.local 97 | .env.local 98 | 99 | # parcel-bundler cache (https://parceljs.org/) 100 | .cache 101 | .parcel-cache 102 | 103 | # Next.js build output 104 | .next 105 | out 106 | 107 | # Nuxt.js build / generate output 108 | .nuxt 109 | dist 110 | 111 | # Gatsby files 112 | .cache/ 113 | # Comment in t 114 | -------------------------------------------------------------------------------- /Projects with Docker/second project/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:14.17.0-alpine3.13 2 | WORKDIR /app 3 | COPY . /app 4 | RUN npm install 5 | EXPOSE 5000 6 | CMD node index.js 7 | -------------------------------------------------------------------------------- /Projects with Docker/second project/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app = express(); 3 | const port = 5000; 4 | 5 | app.get('/', (req, res) => { 6 | res.json({ message: 'Hello World!' }); 7 | }); 8 | 9 | app.listen(port, () => { 10 | console.log(`Example app listening at http://localhost:${port}`); 11 | }); 12 | -------------------------------------------------------------------------------- /Projects with Docker/second project/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "second-project", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "second-project", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.18.2" 13 | } 14 | }, 15 | "node_modules/accepts": { 16 | "version": "1.3.8", 17 | "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", 18 | "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", 19 | "dependencies": { 20 | "mime-types": "~2.1.34", 21 | "negotiator": "0.6.3" 22 | }, 23 | "engines": { 24 | "node": ">= 0.6" 25 | } 26 | }, 27 | "node_modules/array-flatten": { 28 | "version": "1.1.1", 29 | "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", 30 | "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" 31 | }, 32 | "node_modules/body-parser": { 33 | "version": "1.20.1", 34 | "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", 35 | "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==", 36 | "dependencies": { 37 | "bytes": "3.1.2", 38 | "content-type": "~1.0.4", 39 | "debug": "2.6.9", 40 | "depd": "2.0.0", 41 | "destroy": "1.2.0", 42 | "http-errors": "2.0.0", 43 | "iconv-lite": "0.4.24", 44 | "on-finished": "2.4.1", 45 | "qs": "6.11.0", 46 | "raw-body": "2.5.1", 47 | "type-is": "~1.6.18", 48 | "unpipe": "1.0.0" 49 | }, 50 | "engines": { 51 | "node": ">= 0.8", 52 | "npm": "1.2.8000 || >= 1.4.16" 53 | } 54 | }, 55 | "node_modules/bytes": { 56 | "version": "3.1.2", 57 | "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", 58 | "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", 59 | "engines": { 60 | "node": ">= 0.8" 61 | } 62 | }, 63 | "node_modules/call-bind": { 64 | "version": "1.0.2", 65 | "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", 66 | "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", 67 | "dependencies": { 68 | "function-bind": "^1.1.1", 69 | "get-intrinsic": "^1.0.2" 70 | }, 71 | "funding": { 72 | "url": "https://github.com/sponsors/ljharb" 73 | } 74 | }, 75 | "node_modules/content-disposition": { 76 | "version": "0.5.4", 77 | "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", 78 | "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", 79 | "dependencies": { 80 | "safe-buffer": "5.2.1" 81 | }, 82 | "engines": { 83 | "node": ">= 0.6" 84 | } 85 | }, 86 | "node_modules/content-type": { 87 | "version": "1.0.5", 88 | "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", 89 | "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", 90 | "engines": { 91 | "node": ">= 0.6" 92 | } 93 | }, 94 | "node_modules/cookie": { 95 | "version": "0.5.0", 96 | "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", 97 | "integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==", 98 | "engines": { 99 | "node": ">= 0.6" 100 | } 101 | }, 102 | "node_modules/cookie-signature": { 103 | "version": "1.0.6", 104 | "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", 105 | "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==" 106 | }, 107 | "node_modules/debug": { 108 | "version": "2.6.9", 109 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", 110 | "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", 111 | "dependencies": { 112 | "ms": "2.0.0" 113 | } 114 | }, 115 | "node_modules/depd": { 116 | "version": "2.0.0", 117 | "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", 118 | "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", 119 | "engines": { 120 | "node": ">= 0.8" 121 | } 122 | }, 123 | "node_modules/destroy": { 124 | "version": "1.2.0", 125 | "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", 126 | "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", 127 | "engines": { 128 | "node": ">= 0.8", 129 | "npm": "1.2.8000 || >= 1.4.16" 130 | } 131 | }, 132 | "node_modules/ee-first": { 133 | "version": "1.1.1", 134 | "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", 135 | "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" 136 | }, 137 | "node_modules/encodeurl": { 138 | "version": "1.0.2", 139 | "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", 140 | "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", 141 | "engines": { 142 | "node": ">= 0.8" 143 | } 144 | }, 145 | "node_modules/escape-html": { 146 | "version": "1.0.3", 147 | "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", 148 | "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==" 149 | }, 150 | "node_modules/etag": { 151 | "version": "1.8.1", 152 | "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", 153 | "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", 154 | "engines": { 155 | "node": ">= 0.6" 156 | } 157 | }, 158 | "node_modules/express": { 159 | "version": "4.18.2", 160 | "resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz", 161 | "integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==", 162 | "dependencies": { 163 | "accepts": "~1.3.8", 164 | "array-flatten": "1.1.1", 165 | "body-parser": "1.20.1", 166 | "content-disposition": "0.5.4", 167 | "content-type": "~1.0.4", 168 | "cookie": "0.5.0", 169 | "cookie-signature": "1.0.6", 170 | "debug": "2.6.9", 171 | "depd": "2.0.0", 172 | "encodeurl": "~1.0.2", 173 | "escape-html": "~1.0.3", 174 | "etag": "~1.8.1", 175 | "finalhandler": "1.2.0", 176 | "fresh": "0.5.2", 177 | "http-errors": "2.0.0", 178 | "merge-descriptors": "1.0.1", 179 | "methods": "~1.1.2", 180 | "on-finished": "2.4.1", 181 | "parseurl": "~1.3.3", 182 | "path-to-regexp": "0.1.7", 183 | "proxy-addr": "~2.0.7", 184 | "qs": "6.11.0", 185 | "range-parser": "~1.2.1", 186 | "safe-buffer": "5.2.1", 187 | "send": "0.18.0", 188 | "serve-static": "1.15.0", 189 | "setprototypeof": "1.2.0", 190 | "statuses": "2.0.1", 191 | "type-is": "~1.6.18", 192 | "utils-merge": "1.0.1", 193 | "vary": "~1.1.2" 194 | }, 195 | "engines": { 196 | "node": ">= 0.10.0" 197 | } 198 | }, 199 | "node_modules/finalhandler": { 200 | "version": "1.2.0", 201 | "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", 202 | "integrity": "sha512-5uXcUVftlQMFnWC9qu/svkWv3GTd2PfUhK/3PLkYNAe7FbqJMt3515HaxE6eRL74GdsriiwujiawdaB1BpEISg==", 203 | "dependencies": { 204 | "debug": "2.6.9", 205 | "encodeurl": "~1.0.2", 206 | "escape-html": "~1.0.3", 207 | "on-finished": "2.4.1", 208 | "parseurl": "~1.3.3", 209 | "statuses": "2.0.1", 210 | "unpipe": "~1.0.0" 211 | }, 212 | "engines": { 213 | "node": ">= 0.8" 214 | } 215 | }, 216 | "node_modules/forwarded": { 217 | "version": "0.2.0", 218 | "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", 219 | "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", 220 | "engines": { 221 | "node": ">= 0.6" 222 | } 223 | }, 224 | "node_modules/fresh": { 225 | "version": "0.5.2", 226 | "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", 227 | "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", 228 | "engines": { 229 | "node": ">= 0.6" 230 | } 231 | }, 232 | "node_modules/function-bind": { 233 | "version": "1.1.1", 234 | "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", 235 | "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" 236 | }, 237 | "node_modules/get-intrinsic": { 238 | "version": "1.2.0", 239 | "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.0.tgz", 240 | "integrity": "sha512-L049y6nFOuom5wGyRc3/gdTLO94dySVKRACj1RmJZBQXlbTMhtNIgkWkUHq+jYmZvKf14EW1EoJnnjbmoHij0Q==", 241 | "dependencies": { 242 | "function-bind": "^1.1.1", 243 | "has": "^1.0.3", 244 | "has-symbols": "^1.0.3" 245 | }, 246 | "funding": { 247 | "url": "https://github.com/sponsors/ljharb" 248 | } 249 | }, 250 | "node_modules/has": { 251 | "version": "1.0.3", 252 | "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", 253 | "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", 254 | "dependencies": { 255 | "function-bind": "^1.1.1" 256 | }, 257 | "engines": { 258 | "node": ">= 0.4.0" 259 | } 260 | }, 261 | "node_modules/has-symbols": { 262 | "version": "1.0.3", 263 | "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", 264 | "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", 265 | "engines": { 266 | "node": ">= 0.4" 267 | }, 268 | "funding": { 269 | "url": "https://github.com/sponsors/ljharb" 270 | } 271 | }, 272 | "node_modules/http-errors": { 273 | "version": "2.0.0", 274 | "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", 275 | "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", 276 | "dependencies": { 277 | "depd": "2.0.0", 278 | "inherits": "2.0.4", 279 | "setprototypeof": "1.2.0", 280 | "statuses": "2.0.1", 281 | "toidentifier": "1.0.1" 282 | }, 283 | "engines": { 284 | "node": ">= 0.8" 285 | } 286 | }, 287 | "node_modules/iconv-lite": { 288 | "version": "0.4.24", 289 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", 290 | "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", 291 | "dependencies": { 292 | "safer-buffer": ">= 2.1.2 < 3" 293 | }, 294 | "engines": { 295 | "node": ">=0.10.0" 296 | } 297 | }, 298 | "node_modules/inherits": { 299 | "version": "2.0.4", 300 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", 301 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" 302 | }, 303 | "node_modules/ipaddr.js": { 304 | "version": "1.9.1", 305 | "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", 306 | "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", 307 | "engines": { 308 | "node": ">= 0.10" 309 | } 310 | }, 311 | "node_modules/media-typer": { 312 | "version": "0.3.0", 313 | "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", 314 | "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", 315 | "engines": { 316 | "node": ">= 0.6" 317 | } 318 | }, 319 | "node_modules/merge-descriptors": { 320 | "version": "1.0.1", 321 | "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", 322 | "integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==" 323 | }, 324 | "node_modules/methods": { 325 | "version": "1.1.2", 326 | "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", 327 | "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", 328 | "engines": { 329 | "node": ">= 0.6" 330 | } 331 | }, 332 | "node_modules/mime": { 333 | "version": "1.6.0", 334 | "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", 335 | "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", 336 | "bin": { 337 | "mime": "cli.js" 338 | }, 339 | "engines": { 340 | "node": ">=4" 341 | } 342 | }, 343 | "node_modules/mime-db": { 344 | "version": "1.52.0", 345 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", 346 | "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", 347 | "engines": { 348 | "node": ">= 0.6" 349 | } 350 | }, 351 | "node_modules/mime-types": { 352 | "version": "2.1.35", 353 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", 354 | "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", 355 | "dependencies": { 356 | "mime-db": "1.52.0" 357 | }, 358 | "engines": { 359 | "node": ">= 0.6" 360 | } 361 | }, 362 | "node_modules/ms": { 363 | "version": "2.0.0", 364 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 365 | "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" 366 | }, 367 | "node_modules/negotiator": { 368 | "version": "0.6.3", 369 | "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", 370 | "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", 371 | "engines": { 372 | "node": ">= 0.6" 373 | } 374 | }, 375 | "node_modules/object-inspect": { 376 | "version": "1.12.3", 377 | "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz", 378 | "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==", 379 | "funding": { 380 | "url": "https://github.com/sponsors/ljharb" 381 | } 382 | }, 383 | "node_modules/on-finished": { 384 | "version": "2.4.1", 385 | "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", 386 | "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", 387 | "dependencies": { 388 | "ee-first": "1.1.1" 389 | }, 390 | "engines": { 391 | "node": ">= 0.8" 392 | } 393 | }, 394 | "node_modules/parseurl": { 395 | "version": "1.3.3", 396 | "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", 397 | "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", 398 | "engines": { 399 | "node": ">= 0.8" 400 | } 401 | }, 402 | "node_modules/path-to-regexp": { 403 | "version": "0.1.7", 404 | "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", 405 | "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==" 406 | }, 407 | "node_modules/proxy-addr": { 408 | "version": "2.0.7", 409 | "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", 410 | "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", 411 | "dependencies": { 412 | "forwarded": "0.2.0", 413 | "ipaddr.js": "1.9.1" 414 | }, 415 | "engines": { 416 | "node": ">= 0.10" 417 | } 418 | }, 419 | "node_modules/qs": { 420 | "version": "6.11.0", 421 | "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", 422 | "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", 423 | "dependencies": { 424 | "side-channel": "^1.0.4" 425 | }, 426 | "engines": { 427 | "node": ">=0.6" 428 | }, 429 | "funding": { 430 | "url": "https://github.com/sponsors/ljharb" 431 | } 432 | }, 433 | "node_modules/range-parser": { 434 | "version": "1.2.1", 435 | "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", 436 | "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", 437 | "engines": { 438 | "node": ">= 0.6" 439 | } 440 | }, 441 | "node_modules/raw-body": { 442 | "version": "2.5.1", 443 | "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", 444 | "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", 445 | "dependencies": { 446 | "bytes": "3.1.2", 447 | "http-errors": "2.0.0", 448 | "iconv-lite": "0.4.24", 449 | "unpipe": "1.0.0" 450 | }, 451 | "engines": { 452 | "node": ">= 0.8" 453 | } 454 | }, 455 | "node_modules/safe-buffer": { 456 | "version": "5.2.1", 457 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", 458 | "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", 459 | "funding": [ 460 | { 461 | "type": "github", 462 | "url": "https://github.com/sponsors/feross" 463 | }, 464 | { 465 | "type": "patreon", 466 | "url": "https://www.patreon.com/feross" 467 | }, 468 | { 469 | "type": "consulting", 470 | "url": "https://feross.org/support" 471 | } 472 | ] 473 | }, 474 | "node_modules/safer-buffer": { 475 | "version": "2.1.2", 476 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 477 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" 478 | }, 479 | "node_modules/send": { 480 | "version": "0.18.0", 481 | "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", 482 | "integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==", 483 | "dependencies": { 484 | "debug": "2.6.9", 485 | "depd": "2.0.0", 486 | "destroy": "1.2.0", 487 | "encodeurl": "~1.0.2", 488 | "escape-html": "~1.0.3", 489 | "etag": "~1.8.1", 490 | "fresh": "0.5.2", 491 | "http-errors": "2.0.0", 492 | "mime": "1.6.0", 493 | "ms": "2.1.3", 494 | "on-finished": "2.4.1", 495 | "range-parser": "~1.2.1", 496 | "statuses": "2.0.1" 497 | }, 498 | "engines": { 499 | "node": ">= 0.8.0" 500 | } 501 | }, 502 | "node_modules/send/node_modules/ms": { 503 | "version": "2.1.3", 504 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", 505 | "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" 506 | }, 507 | "node_modules/serve-static": { 508 | "version": "1.15.0", 509 | "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz", 510 | "integrity": "sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==", 511 | "dependencies": { 512 | "encodeurl": "~1.0.2", 513 | "escape-html": "~1.0.3", 514 | "parseurl": "~1.3.3", 515 | "send": "0.18.0" 516 | }, 517 | "engines": { 518 | "node": ">= 0.8.0" 519 | } 520 | }, 521 | "node_modules/setprototypeof": { 522 | "version": "1.2.0", 523 | "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", 524 | "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" 525 | }, 526 | "node_modules/side-channel": { 527 | "version": "1.0.4", 528 | "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", 529 | "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", 530 | "dependencies": { 531 | "call-bind": "^1.0.0", 532 | "get-intrinsic": "^1.0.2", 533 | "object-inspect": "^1.9.0" 534 | }, 535 | "funding": { 536 | "url": "https://github.com/sponsors/ljharb" 537 | } 538 | }, 539 | "node_modules/statuses": { 540 | "version": "2.0.1", 541 | "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", 542 | "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", 543 | "engines": { 544 | "node": ">= 0.8" 545 | } 546 | }, 547 | "node_modules/toidentifier": { 548 | "version": "1.0.1", 549 | "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", 550 | "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", 551 | "engines": { 552 | "node": ">=0.6" 553 | } 554 | }, 555 | "node_modules/type-is": { 556 | "version": "1.6.18", 557 | "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", 558 | "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", 559 | "dependencies": { 560 | "media-typer": "0.3.0", 561 | "mime-types": "~2.1.24" 562 | }, 563 | "engines": { 564 | "node": ">= 0.6" 565 | } 566 | }, 567 | "node_modules/unpipe": { 568 | "version": "1.0.0", 569 | "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", 570 | "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", 571 | "engines": { 572 | "node": ">= 0.8" 573 | } 574 | }, 575 | "node_modules/utils-merge": { 576 | "version": "1.0.1", 577 | "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", 578 | "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", 579 | "engines": { 580 | "node": ">= 0.4.0" 581 | } 582 | }, 583 | "node_modules/vary": { 584 | "version": "1.1.2", 585 | "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", 586 | "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", 587 | "engines": { 588 | "node": ">= 0.8" 589 | } 590 | } 591 | } 592 | } 593 | -------------------------------------------------------------------------------- /Projects with Docker/second project/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "second-project", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "express": "^4.18.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # **✨ Docker Tutorial Chapters** 2 | > Small Tips: Starting with `⚡` means that it is a command that you can run in your terminal. 3 | - [**💖 Introduction**](#-introduction) 4 | - [**Why should I use Docker 🐳 ?**](#why-should-i-use-docker--) 5 | - [**Then what is Docker? 🐳**](#then-what-is-docker-) 6 | - [**So we use docker for :**](#so-we-use-docker-for--) 7 | - [**How does Docker work? 🔧**](#how-does-docker-work-) 8 | - [**Example of Docker in action 💻**](#example-of-docker-in-action-) 9 | - [**What is difference between Docker and Virtual Machine(VM)? 🤔**](#what-is-difference-between-docker-and-virtual-machinevm-) 10 | - [**❗ What is VM?**](#-what-is-vm) 11 | - [**❗ What is Docker?**](#-what-is-docker) 12 | - [**❗ How do they differ?**](#-how-do-they-differ) 13 | - [**How to install Docker 🐳**](#how-to-install-docker-) 14 | - [**Containers , Images and Volumes 📦**](#containers--images-and-volumes-) 15 | - [`⚡ Docker Version`](#-docker-version) 16 | - [**Let's start with Docker 🔥**](#lets-start-with-docker-) 17 | - [**✅ Let's play with Postgresql 🐘**](#-lets-play-with-postgresql-) 18 | - [`⚡ Pulling an image`](#-pulling-an-image) 19 | - [`⚡ Check the images`](#-check-the-images) 20 | - [`⚡ Run a container`](#-run-a-container) 21 | - [`⚡ check the containers`](#-check-the-containers) 22 | - [`⚡ Stop and start a container`](#-stop-and-start-a-container) 23 | - [`⚡ Pull according to the version`](#-pull-according-to-the-version) 24 | - [`⚡ Stop the container`](#-stop-the-container) 25 | - [`⚡ Removing all containers`](#-removing-all-containers) 26 | 27 | - [**✅ Let's play with the mongo 🐲**](#-lets-play-with-the-mongo-) 28 | - [`⚡ Port Mapping`](#-port-mapping) 29 | - [`⚡ Docker Logs`](#-docker-logs) 30 | - [`⚡ Delete the container`](#-delete-the-container) 31 | - [**✅ Let's Connect the mongo express with the mongo ??**](#-lets-connect-the-mongo-express-with-the-mongo-) 32 | - [`⚡ Syntax Understanding`](#-syntax-understanding) 33 | - [`⚡ Better Syntax`](#-better-syntax) 34 | - [`⚡ Lost network finding`](#-lost-network-finding) 35 | - [**Let's Understand the Docker Compose 🐳**](#lets-understand-the-docker-compose-) 36 | - [**Step 1**](#step-1) 37 | - [**Step 2**](#step-2) 38 | - [`⚡ Running the docker-compose file`](#-running-the-docker-compose-file) 39 | - [**Step 3 (Data Persistence)**](#step-3-data-persistence) 40 | - [`⚡ Creating a volume in docker-compose file`](#-creating-a-volume-in-docker-compose-file) 41 | - [`⚡ Stop running all containers`](#-stop-running-all-containers) 42 | - [**Our First Project with Docker 🚀**](#our-first-project-with-docker-) 43 | - [`⚡ Python Flask App`](#-python-flask-app) 44 | - [`⚡ Build the docker image`](#-build-the-docker-image) 45 | - [`⚡ Run the docker image`](#-run-the-docker-image) 46 | - [`⚡ Stop the docker container`](#-stop-the-docker-container) 47 | - [`⚡ Mapping the port`](#-mapping-the-port) 48 | - [`⚡ Push the docker image to the docker hub`](#-push-the-docker-image-to-the-docker-hub) 49 | - [**Our Second Project with Docker 🚀**](#our-second-project-with-docker-) 50 | - [`⚡ NodeJs Setup`](#-nodejs-setup) 51 | - [`⚡ Login to the docker hub`](#-login-to-the-docker-hub) 52 | - [`⚡ Check the container id`](#-check-the-container-id) 53 | - [`⚡ Stop the container`](#-stop-the-container) 54 | - [`⚡ Kill the container`](#-kill-the-container) 55 | - [`⚡ Remove the container`](#-remove-the-container) 56 | - [`⚡ Remove the image`](#-remove-the-image) 57 | - [`⚡ Pull the docker image`](#-pull-the-docker-image) 58 | - [**🥰 What did we understand from these two projects?**](#-what-did-we-understand-from-these-two-projects) 59 | - [**✨ Docker Best CLI Cheat Sheet**](#-docker-cli-cheat-sheet) 60 | - [**📌 Conclusion**](#-conclusion) 61 | 62 | ### 📑 Another Platform For Better Reading Experience 63 | ![Docker Tutorial](https://img.shields.io/badge/Docker-Tutorial-blue.svg) 64 | - [**CodeXam**](https://codexam.vercel.app/docs/docker) - Best ✨ 65 | - [**GitHub**](https://github.com/Subham-Maity/docker_tutorial) - Good ✨ 66 | - [**Hashnode**](https://codexam.hashnode.dev/docker-tutorial-master-docker-from-scratch) - Good ✨ 67 | - [**dev.to**](https://dev.to/codexam/docker-tutorial-5f7b) - Good ✨ 68 | ___________ 69 | # 💖 Introduction 70 | 71 | This tutorial is designed for complete beginners to advanced users who want to learn Docker from scratch. It covers everything you need to know about Docker, from installation and configuration to creating and running containers, `images`, and `volumes`. It also explains the concepts and benefits of Docker, such as `port mapping`, `networking`, `security`, and `compose`. By the end of this tutorial, you will have no doubts about how to use Docker effectively and efficiently. 72 | 73 | This tutorial is also full of practical examples and projects that will help you apply what you learn and gain hands-on experience with Docker. You will learn how to create a Python Flask app, a Node.js app, a Postgresql database, and a Mongo Express web interface using Docker. You will also learn how to build, run, stop, delete, and push your Docker images and containers. 74 | 75 | I have created this tutorial with the aim of helping you learn Docker in a fun and easy way. If you appreciate his effort and find this tutorial useful, please give it a star (⭐) on GitHub and share it with your friends. 76 | 77 | So what are you waiting for? Let's dive into the world of Docker and see what it can do for you! 78 | 79 | ____________ 80 | # Why should I use Docker 🐳 ? 81 | 82 | Have you ever faced this problem? 😱 83 | 84 | > Your code works fine on your dev environment, but when you publish it on the server, it breaks and gives you errors. You don't know why ,and you have to fix it quickly. You find out that you forgot to install a dependency or you used a different version of a tool. 85 | 86 | If yes, then you need Docker! 🙌 87 | 88 | Docker is a tool that lets you create and run **containers**. Containers are like boxes that have everything your app needs to run. They have the same files, programs, and settings on any environment. You can use the same container on your dev environment, your server, or any other computer. 📦 89 | 90 | Using Docker will make your life easier because: 😊 91 | 92 | - You won't have to worry about missing or mismatched dependencies on your server. Your container will have them all. 93 | - You won't have to install or configure anything on your dev environment. You can just use a container that has everything ready for you. 94 | - You can use containers for old or new projects. You can keep the dependencies that you need without affecting other projects or systems. 95 | - You can use containers to run your app on the cloud. You can also use tools like Docker Swarm or Kubernetes to manage multiple containers. 96 | 97 | Docker is awesome and you should try it! 🚀 98 | 99 | 100 | ## **Then what is Docker?** 🐳 101 | Docker is a software platform that lets you run applications inside containers. Think of containers like virtual machines, but lighter and more efficient! 🚀 102 | 103 | ### So we use docker for : 104 | - Simplifies application deployment: Package your application and all its dependencies into a container that can run on any machine with Docker installed. 📦 105 | - Increases portability: Move Docker containers easily from one environment to another, like from a developer's laptop to a production server. 🚚 106 | - Improves scalability: Quickly spin up multiple instances of your application to handle increased traffic. 🔝 107 | 108 | ## **How does Docker work?** 🔧 109 | Docker creates containers, which are isolated environments with their own filesystem, network, and processes. Each container runs a specific application along with its dependencies. 📁 110 | 111 | To create a container, you first need to create a Docker image, which is a snapshot of your application and its dependencies. You can create an image by writing a Dockerfile, a script that specifies the instructions for building the image. 📜 112 | 113 | Once you have an image, you can use it to create a container by running the `docker run` command. This starts a new container based on the image and runs the application inside it. 🏃‍♂️ 114 | 115 | ### **Example of Docker in action** 💻 116 | Let's say you have a web application that uses Node.js and MongoDB. Normally, you would need to install Node.js and MongoDB on your server and configure them to work together. With Docker, you can create two separate containers, one for Node.js and one for MongoDB, and run them on the same server 117 | 118 | To do this, you would create two Docker images: one for the Node.js application and one for the MongoDB database. Then you would use the docker run command to start both containers, making sure to link them together so that the Node.js container can communicate with the MongoDB container. 119 | 120 | By using Docker, you can simplify the deployment of your web application, make it more portable, and improve its scalability. 121 | ### What is difference between Docker and Virtual Machine(VM)? 🤔 122 | #### ❗ What is VM? 123 | 124 | VM stands for virtual machine. A virtual machine is also like a mini-computer that runs on your main computer. But unlike a container, a virtual machine has its own operating system. This means that it can run any kind of application, regardless of the operating system of your main computer. 125 | 126 | The advantage of using virtual machines is that they are very secure and isolated. They don't share anything with your main computer or with other virtual machines. If something goes wrong with one virtual machine, it won't affect the others. You can also run different operating systems on different virtual machines. 127 | 128 | #### ❗ What is Docker? 129 | 130 | Docker is a tool that lets you create and run containers. Containers are like virtual machines, but they don't have their own operating system. They only have the files, programs, and settings that they need to run their application. This makes them very efficient and fast. 131 | 132 | Docker doesn't have kernel-level virtualization like virtual machines do. Instead, it uses a container engine to create containers. This makes Docker much lighter and faster than virtual machines. 133 | 134 | #### ❗ How do they differ? 135 | 136 | The main difference between docker and vm is how they use the resources of your main computer. Docker containers share the same operating system as your main computer. They only use the software that they need to run their application. This makes them very efficient and fast. 137 | 138 | Virtual machines don't share anything with your main computer. They have their own operating system and hardware resources. This makes them more independent and secure, but also more heavy and slow. 139 | 140 | Here is a table that summarizes some of the key differences between docker and vm: 141 | 142 | | Topic | Docker | VM | 143 | | --- | --- | --- | 144 | | Operating system | Shared | Separate | 145 | | Performance | Fast | Slow | 146 | | Portability | Easy | Hard | 147 | | Security | Low | High | 148 | 149 | ### How to install Docker 🐳 150 | 151 | 1. To get started, open this website: https://docs.docker.com/ and click on the **_Download and Install_** button. Then select the **_Docker Desktop for Windows_** or **_Docker Desktop for Mac_** or **_Docker Desktop for Linux_** button depending on your operating system. This will take you to the download page. 🖱️ 152 | 2. Follow the instructions to install Docker Desktop for your operating system. You may need to restart your computer after the installation. 🔄 153 | 3. Once you have installed Docker Desktop, you will see an interface like this: 🖥️ 154 | 155 | ![image](https://user-images.githubusercontent.com/97989643/231662759-9ed07c47-6066-4da4-9154-837c5861880c.png) 156 | 157 | 4. Now you can sign in to your Docker account or create a new one if you don't have one already. 🔑 158 | 5. On the interface, you will notice three sections: **_Containers_**, **_Images_** and **_Volumes_**. These are the main components of Docker that you need to know about. 📦 159 | 160 | 161 | ## **Containers , Images and Volumes** 📦 162 | 163 | - **Containers** are like boxes that you can put things in. Each box has its own things that are separate from the other boxes. You can open and close a box without affecting the other boxes or the room. Containers are like boxes that have their own files, programs, and settings that are separate from the other containers or the computer. You can create and delete containers without affecting the other containers or the computer. Containers are fast and easy to use because they use the same system as the computer and do not need to start a whole new system like virtual machines do. 164 | - **Images** are like recipes for making containers. They tell you what ingredients and steps you need to make a container. You can use an existing recipe from a public place like Docker Hub, or you can write your own recipe using a Dockerfile. Recipes do not change once they are written. You can use the same recipe to make many containers with the same ingredients and steps. 165 | > let's say you have a project that consists of a web application written in Node.js, a backend server written in Java, and a machine learning component written in Python. You can create three separate Docker images for each of these components, each with its own dependencies and configurations, and then use them to create containers that can run the entire project. 166 | 167 | > For instance, you can create a Docker image for the Node.js application by specifying the base image as node and then copying the application code into the container. You can then build and tag the image with a specific name, like my-node-app. 168 | - **Volumes** are like external drives that you can connect to your containers. They let you save data that your containers make or use, such as databases, logs, or configuration files. Volumes do not get deleted when you delete a container. You can also share volumes among many containers or access them from the computer. Volumes are the best way to save data with Docker because they are easier to back up, move, and manage than other ways of saving data. 169 | #### ⚡ Docker Version 170 | To check if docker is installed or not, you can run this command in your terminal: 171 | ```bash 172 | docker --version 173 | ``` 174 | or 175 | ```bash 176 | docker version 177 | ``` 178 | or 179 | ```bash 180 | docker -v 181 | ``` 182 | 183 | 184 | ## **Let's start with Docker** 🔥 185 | If you want to learn the actual thing, you should work on real-world problems that challenge you and make you think. As you try to fix the issues and errors that arise, you will learn more concepts and skills along the way. That’s why I’ll focus on showing you how to work on a real-world application with docker, and how to troubleshoot any problems that may occur. You will also learn how to read documentation, understand complexity, and solve any problem that comes your way. Let’s dive right in! 186 | ### ✅ **Let's play with Postgresql** 🐘 187 | #### ⚡ Pulling an image 188 | 1. First open this website for postgresql: https://hub.docker.com/_/postgres 189 | you will see this right side of the page: 190 | ```bash 191 | docker pull postgres 192 | ``` 193 | 194 | 2. Open your terminal and type this command: 195 | ```bash 196 | docker pull postgres 197 | ``` 198 | > - You can check docker is installed or not by typing this command: `docker --version` 199 | > - You can visit the docker documentation for pull command: https://docs.docker.com/engine/reference/commandline/pull/ 200 | > - Pulling an image doesn't mean installing it. It just means that you are downloading the image from the Docker Hub to your computer. 201 | > - It will download the latest version of the image. If you want to download a specific version, you can add the version number after the image name. For example, `docker pull postgres:9.6.2` will download the 9.6.2 version of the image. 202 | #### ⚡ Check the images 203 | 3. Now may be you want to check your images, so type this command: 204 | ```bash 205 | docker image ls 206 | ``` 207 | > - You can visit the docker documentation for image command:https://docs.docker.com/engine/reference/commandline/image/ 208 | 209 | You can see the output like this: 210 | ```bash 211 | REPOSITORY TAG IMAGE ID CREATED SIZE 212 | postgres latest ceccf204404e 30 hours ago 379MB 213 | ``` 214 | > Even you can open the docker desktop and check the images there ,and you will see the same output. 215 | > - You can visit for ps command: https://docs.docker.com/engine/reference/commandline/ps/ 216 | 217 | #### ⚡ Run a container 218 | 219 | 4. Now if you want to run postgresql, first you should visit postgresql documentation: https://hub.docker.com/_/postgres check for `How to use this image` 220 | - You will see this: 221 | ```bash 222 | $ docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres 223 | ``` 224 | 5. Now open your terminal you need to modify this command: 225 | ```bash 226 | docker run -e POSTGRES_PASSWORD=mysecretpassword postgres 227 | ``` 228 | > here e is for environment variable, and POSTGRES_PASSWORD is the environment variable name, and mysecretpassword is the value of the environment variable. 229 | now you can 230 | > here e is for environment variable, and POSTGRES_PASSWORD is the environment variable name, and mysecretpassword is the value of the environment variable. 231 | now you can see the output like this: 232 | ```bash 233 | PostgreSQL init process complete; ready for start up. 234 | 235 | 2023-04-13 13:00:11.415 UTC [1] LOG: starting PostgreSQL 15.2 (Debian 15.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit 236 | 2023-04-13 13:00:11.431 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 237 | 2023-04-13 13:00:11.432 UTC [1] LOG: listening on IPv6 address "::", port 5432 238 | 2023-04-13 13:00:11.443 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" 239 | 2023-04-13 13:00:11.455 UTC [62] LOG: database system was shut down at 2023-04-13 13:00:11 UTC 240 | 2023-04-13 13:00:11.465 UTC [1] LOG: database system is ready to accept connections 241 | ``` 242 | 243 | > - If you want to shut down you can simply type `wsl --shutdown` in your terminal. 244 | > - If you don’t interact with the container, it will eventually exit. However, you can keep the container running by interacting with it or by running it in detached mode using the -d flag when starting the container. For example, `docker run -d -e POSTGRES_PASSWORD=mysecretpassword postgres` will start the container in detached mode. 245 | 246 | 6. Now hit `docker run -e POSTGRES_PASSWORD=mysecretpassword -d postgres` 247 | > One Id will be generated 248 | 7. Now if you want to check your containers on the software, you can see `the another container` is running with another name. 249 | 250 | #### ⚡ check the containers 251 | 252 | 8. Now if you want to check your containers on the terminal, you can type this command: 253 | ```bash 254 | docker ps 255 | ``` 256 | > you will see the output like this: 257 | ```bash 258 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 259 | 8fee7f681552 postgres "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 5432/tcp beautiful_curie 260 | ``` 261 | #### ⚡ Stop and start a container 262 | 263 | 9. Now if you want to stop the container, you can type this command: 264 | ```bash 265 | docker stop my_container 266 | ``` 267 | > - in my case, my_container is beautiful_curie 268 | > - you can also mention your container id instead of the name. 269 | > - or you can go to the docker desktop and click on the stop button. 270 | 10. Now again if you want to run the container, you can type this command: 271 | ```bash 272 | docker start my_container 273 | ``` 274 | > - in my case, my_container is beautiful_curie 275 | > - you can do the same thing with the docker desktop. 276 | 277 | 278 | #### ⚡ Pull according to the version 279 | I want to spin up two machines one with postgres latest one with postgres 13.8 rest of the stuff will be same 280 | 281 | 11. First hit this command: 282 | ```bash 283 | docker run --name postgres-lates -e POSTGRES_PASSWORD=mysecretpassword -d postgres 284 | ``` 285 | > Here postgres-lates is the name of the container 286 | 287 | 12. Now hit this command: 288 | ```bash 289 | docker run --name postgres-old -e POSTGRES_PASSWORD=mysecretpassword -d postgres:13.8 290 | ``` 291 | you will see the output like this: 292 | ```bash 293 | Unable to find image 'postgres:13.8' locally 294 | 13.8: Pulling from library/postgres 295 | e9995326b091: Pull complete 296 | a0cb03f17886: Pull complete 297 | bb26f7e78134: Pull complete 298 | c8e073b7ae91: Pull complete 299 | 99b5b1679915: Pull complete 300 | 55c520fc03c5: Pull complete 301 | d0ac84d6672c: Pull complete 302 | 4effb95d5849: Pull complete 303 | 97fd2548fc1e: Pull complete 304 | 43e7f13e3769: Pull complete 305 | 2898936d5b2e: Pull complete 306 | b4b731b0864d: Pull complete 307 | fbd79522dd4c: Pull complete 308 | Digest: sha256:2b31dc28ab2a687bb191e66e69c2534c9c74107ddb3192ff22a04de386425905 309 | Status: Downloaded newer image for postgres:13.8 310 | 309ecc4e9fd6173f9c6173a2b3a07f8cb656e1cefed0b2b92418bbcc10df7379 311 | ``` 312 | > First it will check whether the image is present in your local machine or not, if not it will download the image from the docker hub. 313 | 314 | 13. Now if you check in your docker desktop, you will see two containers are running. 315 | 316 | ![image](https://user-images.githubusercontent.com/97989643/231970823-caca3e0c-df6c-41dc-8470-07491322ff91.png) 317 | 318 | 14. Now you might notice the port number is not showing in the docker desktop so you can check the port number by typing this command: 319 | ```bash 320 | docker port postgres-lates 321 | ``` 322 | or, 323 | ```bash 324 | docker ps 325 | ``` 326 | ![image](https://user-images.githubusercontent.com/97989643/231972961-1370a49a-fda0-47fa-9354-64cc7ad4b9c6.png) 327 | 328 | > Here you will notice the port number same for both the containers like 5432/tcp this means the port number is 5432. Port number is where the postgres is running if the same port number is running in your local machine then you can’t run the postgres in your local machine. 329 | > - For that you should learn about docker container you can check my blog on docker container [here](https://docs.docker.com/engine/reference/commandline/container/) 330 | 331 | #### ⚡ Stop the container 332 | 333 | 15. Here I want to learn about docker container stop so you can check this docker container stop [here](https://docs.docker.com/engine/reference/commandline/container_stop/) 334 | So I will stop the container by typing this command: 335 | ```bash 336 | docker container stop postgres-lates 337 | ``` 338 | > - you can also give the container id instead of the name. 339 | > - no if you hit the command `docker container ls` you will see the container is stopped. 340 | > - you can also use docker `container ls -a` to see all the containers. 341 | ![image](https://user-images.githubusercontent.com/97989643/231978583-54f7b958-77ed-41a6-84ad-424ccc83ca7d.png) 342 | 343 | 344 | #### ⚡ Removing all containers 345 | 346 | 16. Now if you want to remove all containers you can type this command: 347 | - Before removing the container you should check how I find this on internet or stackoverflow check this [here](https://stackoverflow.com/questions/17236796/how-to-remove-old-docker-containers) 348 | ```bash 349 | docker container prune 350 | ``` 351 | you will see the output like this: 352 | ```bash 353 | WARNING! This will remove all stopped containers. 354 | Are you sure you want to continue? [y/N] y 355 | Deleted Containers: 356 | 309ecc4e9fd6173f9c6173a2b3a07f8cb656e1cefed0b2b92418bbcc10df7379 357 | e5dbcda75300b6cebb4c40aad10cfdb4245ce5ac526efef42b02da7e78ea6ed9 358 | 8fee7f68155231c08da8a1441be7c196c8fae68f4cb72fb8d35e53669683d44c 359 | 04d5b89229259396524f85a0fb222c2f24bc9207e4912240277667fac4a067c6 360 | 361 | Total reclaimed space: 63B 362 | ``` 363 | > This is dangerous command so be careful while using this command. 364 | 365 | #### ⚡ Check volumes 366 | 367 | 17. Now if you want to check the volumes you can type this command: 368 | ```bash 369 | docker volume ls 370 | ``` 371 | ![image](https://user-images.githubusercontent.com/97989643/232023685-45f4a982-3a99-49d9-be00-71703938b8aa.png) 372 | 373 | ### ✅ **Let's play with the mongo** 🐲 374 | 1. First pull the mongo image from the docker hub 375 | ```bash 376 | docker pull mongo 377 | ``` 378 | 2. Now create a container 379 | ```bash 380 | docker run --name my-mongo-one -d mongo 381 | ``` 382 | 3. Now check the container 383 | ```bash 384 | docker container ls 385 | ``` 386 | ![image](https://user-images.githubusercontent.com/97989643/232030798-295453ae-b063-47cc-8f76-15a079209067.png) 387 | 388 | #### ⚡ Port Mapping 389 | 4. One version of the mongo is running now I want to run another version of the mongo so I will map the port number. 390 | ```bash 391 | docker run --name my-mongo-one -p 4000:27017 -d mongo 392 | ``` 393 | then 394 | 395 | ```bash 396 | docker run --name my-mongo-two -p 4001:27017 -d mongo 397 | ``` 398 | ![image](https://user-images.githubusercontent.com/97989643/232038856-61110a10-ed36-4294-8f07-bdba91029de9.png) 399 | 400 | #### ⚡ Docker Logs 401 | 402 | 5. Now if you want to see the logs of the container you can type this command: 403 | 404 | > Logs is basically to see what is happening inside the container and all the details of the container. 405 | 406 | ```bash 407 | docker logs my-mongo-one 408 | ``` 409 | - You can id instead of the name. 410 | 411 | #### ⚡ Delete the container 412 | 413 | 6. Let's delete the container 414 | ```bash 415 | docker container rm my-mongo-one 416 | ``` 417 | ### ✅ **Let's Connect the mongo express with the mongo** ?? 418 | 419 | > Our idea is to create a container of the mongo and another container of the mongo express now we will connect the mongo express with the mongo container because mongo express depends on the mongo container. 420 | > - You can assume this Idea for any kind of project. 421 | > - Also in this case you have to give a same network name to both the containers. 422 | 423 | 1. First open the documentation of mongo [here](https://hub.docker.com/_/mongo) and mongo express [here](https://hub.docker.com/_/mongo-express) and check the environment variables and ports and also check docker's documentation on [network](https://docs.docker.com/network/) 424 | 425 | #### ⚡ Syntax Understanding 426 | 427 | 1. If you want to create mongo with network port environment variables you can type this command: 428 | ```bash 429 | docker run -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=password --name mongodb --net mongo-network -d mongo 430 | ``` 431 | - `docker` means you are using docker. 432 | - `run` means you are running the container. 433 | - `-p` means you are mapping the port number in this case you are mapping the port number 27017 to 27017. 434 | - `-e` means you are giving the environment variables if you open mongo documentation you will see the environment variables. 435 | - `--name` means you are giving the name to the container. 436 | - `--net` means you are giving the network name to the container in this case you are giving the network name `mongo-network`. 437 | - `-d` means you are running the container in the background d means detached. 438 | - `mongo` means you are pulling the mongo image from the docker hub. 439 | #### ⚡ Better Syntax 440 | But you can write this even better way: 441 | 442 | ```bash 443 | docker run -d \ 444 | -p 27017:27017 \ 445 | -e MONGO_INITDB_ROOT_USERNAME=admin \ 446 | -e MONGO_INITDB_ROOT_PASSWORD=password \ 447 | --name mongodb \ 448 | --net mongo-network \ 449 | mongo 450 | 451 | ``` 452 | > if you see any network not found error you can create the network by typing this command:```docker network create mongo-network``` 453 | 454 | #### ⚡ Lost network finding 455 | 2. Assume you have created the network and you have created the container but you have lost the network name so you can find the network name by typing this command: 456 | 457 | ```bash 458 | docker network ls 459 | ``` 460 | ![image](https://user-images.githubusercontent.com/97989643/232096253-34039dbe-39c6-4ed4-89f2-40546808b6c4.png) 461 | 462 | 3. Now we are going to create the mongo express container: 463 | 464 | ```bash 465 | docker run -d \ 466 | -p 8081:8081 \ 467 | -e ME_CONFIG_MONGODB_ADMINUSERNAME=admin \ 468 | -e ME_CONFIG_MONGODB_ADMINPASSWORD=password \ 469 | -e ME_CONFIG_MONGODB_SERVER=mongodb \ 470 | --name mongo-express \ 471 | --net mongo-network \ 472 | mongo-express 473 | ``` 474 | 4. Now check the container 475 | ```bash 476 | docker container ls 477 | ``` 478 | 5. Now you can run mongo express on the browser by typing this url: 479 | ```bash 480 | http://localhost:8081 481 | ``` 482 | ![image](https://user-images.githubusercontent.com/97989643/232122188-1ad225d8-7c06-4ffb-b2a2-be308c36c5ed.png) 483 | 484 | ## **Let's Understand the Docker Compose** 🐳 485 | 486 | > Docker Compose is a tool that helps you manage multiple containers as a single application. You define your application’s services in a YAML file and then use a single command to start or stop all the services. This makes it easy to share and collaborate on projects with others 487 | 488 | 1. Create a file named `docker-compose.yml` and install plugins `indent-rainbow` and `docker-compose` 489 | 2. Please use `tab` instead of `space` in this file because yml file is similar to python it strictly follows the indentation. 490 | 3. Create two folder `Codes` and `DockerCompose` 491 | 4. Inside the `DockerCompose` folder create a file named `docker-compose.yml` 492 | > - you can name the file anything but it is a good practice to name it `docker-compose.yml` 493 | > - You can use `indent-rainbow` plugin to make the indentation better. 494 | 495 | Inside the `docker-compose.yml` file type this code: 496 | ### Step 1 497 | #### ⚡ Writing on YML file 498 | ```yml 499 | version: '3' 500 | services: 501 | mongodb: 502 | mongo-express: 503 | ``` 504 | - Whatever you wrote on the terminal you have to write it here. 505 | 506 | ### Step 2 507 | > Your compose file doesn't know which container to run first, so it could run `Express` first or it could run `mongodb` first. We also know that Express relies on `mongodb`, so it could run mongodb first or maybe it could run Express first. But we know that `Express` relies on `mongodb`, so the mongodb containers should be up and running first and then Express should come into the picture. Now there is an option where we can write this container first, then second Express, which is dependent on mongodb. Or we can keep this Express container up and say 'hey, you keep on restarting until you find a connection with mongodb.' The majority of the time people will be using something like 'depends on' for that. So for that, we have to write depends on then we have to write the name of the container, which is mongodb." 508 | 509 | ```yml 510 | version: '3' 511 | services: 512 | mongodb: 513 | image: mongo 514 | container_name: mongodb 515 | ports: 516 | - 27017:27017 517 | environment: 518 | - MONGO_INITDB_ROOT_USERNAME=admin 519 | - MONGO_INITDB_ROOT_PASSWORD=password 520 | mongo-express: 521 | image: mongo-express 522 | restart: always 523 | container_name: mongo-express 524 | ports: 525 | - 8081:8081 526 | environment: 527 | - ME_CONFIG_MONGODB_ADMINUSERNAME=admin 528 | - ME_CONFIG_MONGODB_ADMINPASSWORD=password 529 | - ME_CONFIG_MONGODB_SERVER=mongodb 530 | ``` 531 | > - `version` means you are using docker-compose version 3. 532 | > - `services` means you are creating the services. 533 | > - `mongodb` means you are creating the mongodb service. 534 | > - `image` means you are pulling the image from the docker hub. 535 | > - `container_name` means you are giving the name to the container. 536 | > - `ports` means you are mapping the port number in this case you are mapping the port number 27017 to 27017. 537 | > - `environment` means you are giving the environment variables if you open mongo documentation you will see the environment variables. 538 | > - `restart` means you are saying that if the container is stopped then restart it. 539 | > - `depends_on` means you are saying that this container depends on the mongodb container. 540 | > - `ME_CONFIG_MONGODB_SERVER` means you are giving the name of the mongodb container. 541 | > - `ME_CONFIG_MONGODB_ADMINUSERNAME` means you are giving the username of the mongodb container. 542 | > - `ME_CONFIG_MONGODB_ADMINPASSWORD` means you are giving the password of the mongodb container. 543 | > - `ME_CONFIG_MONGODB_SERVER` means you are giving the name of the mongodb container. 544 | 545 | #### ⚡ Running the docker-compose file 546 | - Now in the terminal type this command: 547 | ```bash 548 | docker-compose -f docker-compose.yml up 549 | ``` 550 | > This will create the container and run the container. But make sure you are in the same directory where the `docker-compose.yml` file is located. 551 | > - `docker-compose` means you are using docker-compose. 552 | > - `-f` means you are giving the file name. 553 | > - `docker-compose.yml` means you are giving the file name. 554 | > - `up` means you are running the container. 555 | 556 | 557 | ![image](https://user-images.githubusercontent.com/97989643/233099836-3f3bea54-a49c-48e3-a89f-f5cc47db756d.png) 558 | 559 | ![image](https://user-images.githubusercontent.com/97989643/233104208-85cee452-56dc-4b9f-80d2-2023ad7045a9.png) 560 | 561 | ![image](https://user-images.githubusercontent.com/97989643/233104637-267f0fc7-c675-4eeb-a19a-ec6a06be4000.png) 562 | 563 | ![image](https://user-images.githubusercontent.com/97989643/233105378-12118b0c-c4bb-4479-9988-b67748209dee.png) 564 | 565 | Now you can see the response in the terminal. 566 | 567 | ![image](https://user-images.githubusercontent.com/97989643/233106828-aa0fc74e-3ce2-4d35-ae7b-6ffbf8dd6150.png) 568 | 569 | - Now stop the container from docker desktop. 570 | - And again run the container from the terminal. 571 | ```bash 572 | docker-compose -f docker-compose.yml up 573 | ``` 574 | You might see `Subham` database again when you visit the localhost:8081. 575 | ![image](https://user-images.githubusercontent.com/97989643/233117646-eee65c16-1902-4228-8911-a0fa27aac277.png) 576 | ### Step 3 (Data Persistence) 577 | > One of the biggest problems in the Docker world is that data doesn’t persist. This means that the container is a removable or detachable item and anything mentioned in the docker-compose file will be removed when you remove the container. This can actually be a good thing when you are making a sensitive application, especially something like a code engine. There is a chance that someone might throw up malicious code that could corrupt your entire system. But with a Docker container, you don’t have to worry too much because everything just goes away after that. However, in this case, we want to keep this data and understand what is keeping it. For this, we need to understand Docker volumes. Docker Desktop sometimes, in fact most of the time, creates automatic volumes for you, especially for databases. It assumes that you might want to keep this database there. This is where something interesting comes into the picture. 578 | 579 | Why do we need to know about data persistence? 580 | > - If you are using a database, you need to know how to persist the data meaning how to keep the data even after you remove the container or even after you restart the container. 581 | > - So here comes the concept of volumes.Volumes are one way to achieve data persistence in a containerized environment. They allow you to store data outside of the container’s file system so that it can be accessed even if the container is removed or restarted. 582 | 583 | #### ⚡ Creating a volume in docker-compose file 584 | 585 | ```yml 586 | version: '3' 587 | services: 588 | mongodb: 589 | image: mongo 590 | container_name: mongodb 591 | ports: 592 | - 27017:27017 593 | environment: 594 | - MONGO_INITDB_ROOT_USERNAME=admin 595 | - MONGO_INITDB_ROOT_PASSWORD=password 596 | volumes: 597 | - mongodb_data:/data/db 598 | mongo-express: 599 | image: mongo-express 600 | restart: always 601 | container_name: mongo-express 602 | ports: 603 | - 8081:8081 604 | environment: 605 | - ME_CONFIG_MONGODB_ADMINUSERNAME=admin 606 | - ME_CONFIG_MONGODB_ADMINPASSWORD=password 607 | - ME_CONFIG_MONGODB_SERVER=mongodb 608 | volumes: 609 | mongodb_data: 610 | driver: local 611 | ``` 612 | - Now again do the same thing as we did in the previous step. 613 | - Stop the container from docker desktop. 614 | - Run the container from the terminal. 615 | - Visit the localhost:8081. 616 | - Create a database. 617 | - Stop the container from docker desktop. 618 | - Run the container from the terminal. 619 | - Visit the localhost:8081. 620 | - Now you can see the database. 621 | ![image](https://user-images.githubusercontent.com/97989643/233134779-06775b0e-b903-4f19-8f1c-2f7f587a9401.png) 622 | **I understand that it is a little bit confusing but don't worry I will explain it in detail.** 623 | 624 | _Let's do some fun stuff so that you can understand it better._ 625 | - step 1: Stop the container by pressing `ctrl+c` in the terminal. 626 | - step 2: Now go to your `docker-compose.yml` file and rename the volume name from `mongodb_data` to `mongodb_data1` like this: 627 | ```yml 628 | version: '3' 629 | services: 630 | mongodb: 631 | image: mongo 632 | container_name: mongodb 633 | ports: 634 | - 27017:27017 635 | environment: 636 | - MONGO_INITDB_ROOT_USERNAME=admin 637 | - MONGO_INITDB_ROOT_PASSWORD=password 638 | volumes: 639 | - mongodb_data1:/data/db 640 | mongo-express: 641 | image: mongo-express 642 | restart: always 643 | container_name: mongo-express 644 | ports: 645 | - 8081:8081 646 | environment: 647 | - ME_CONFIG_MONGODB_ADMINUSERNAME=admin 648 | - ME_CONFIG_MONGODB_ADMINPASSWORD=password 649 | - ME_CONFIG_MONGODB_SERVER=mongodb 650 | volumes: 651 | mongodb_data1: 652 | driver: local 653 | ``` 654 | 655 | ![image](https://user-images.githubusercontent.com/97989643/233131630-518325ca-b01e-43ae-9b6a-4c9685397dea.png) 656 | 657 | - step 4: Now create a database name `SubhamSecond` and create a collection name `SubhamSecondCollection` and add some data. 658 | Start the container again by running the container from the terminal. 659 | ```bash 660 | docker-compose -f docker-compose.yml up 661 | ``` 662 | Now if you visit the localhost:8081 you will see the database. 663 | ![image](https://user-images.githubusercontent.com/97989643/233133685-dccbc53e-049b-4b2d-a888-9ea42de38323.png) 664 | - step 5: Now stop the container from docker desktop or by pressing `ctrl+c` in the terminal. 665 | - step 6: Now again change the `docker-compose.yml` file like this and rename the volume name from `mongodb_data1` to `mongodb_data` means previous volume name. 666 | 667 | ```yml 668 | version: '3' 669 | services: 670 | mongodb: 671 | image: mongo 672 | container_name: mongodb 673 | ports: 674 | - 27017:27017 675 | environment: 676 | - MONGO_INITDB_ROOT_USERNAME=admin 677 | - MONGO_INITDB_ROOT_PASSWORD=password 678 | volumes: 679 | - mongodb_data:/data/db 680 | mongo-express: 681 | image: mongo-express 682 | restart: always 683 | container_name: mongo-express 684 | ports: 685 | - 8081:8081 686 | environment: 687 | - ME_CONFIG_MONGODB_ADMINUSERNAME=admin 688 | - ME_CONFIG_MONGODB_ADMINPASSWORD=password 689 | - ME_CONFIG_MONGODB_SERVER=mongodb 690 | volumes: 691 | mongodb_data: 692 | driver: local 693 | ``` 694 | Now again start the container from the terminal. 695 | ```bash 696 | docker-compose -f docker-compose.yml up 697 | ``` 698 | Now if you visit the localhost:8081 you will see the database `CodeXam` 699 | ![image](https://user-images.githubusercontent.com/97989643/233134930-13081cb3-51e7-44a3-bf55-6e705067d42d.png) 700 | 701 | 702 | So this is called data persistence. Now you can understand why we need to know about data persistence. 703 | You can create as many volumes as you want. If you want to know more about data persistence in docker then you can check out this [link](https://docs.docker.com/storage/volumes/). 704 | 705 | #### ⚡ Stop running all containers 706 | > `ctrl+c` doesn't actually stop the container. It just stops the container from running in the terminal. So if you want to stop the container from running then you can use the following command. 707 | ```bash 708 | docker-compose -f docker-compose.yml down 709 | ``` 710 | 711 | > AWS also provides you like docker hub. You can store your docker images in AWS ECR (Elastic Container Registry). You can check out this [link](https://docs.aws.amazon.com/AmazonECR/latest/userguide/ECR_on_ECS.html) to know more about AWS ECR. 712 | 713 | ## Our First Project with Docker 🚀 714 | > Now we are going to create our first project. 715 | - Step 1: Create a folder name `first project` and inside that create a file name `index.py` and `requirements.txt` 716 | - Step 2: Now create a file name `Dockerfile` and paste the following code in it. 717 | #### ⚡ Python Flask App 718 | ```yml 719 | FROM python:3-alpine3.15 720 | WORKDIR /app 721 | COPY . /app 722 | RUN pip install -r requirements.txt 723 | EXPOSE 5000 724 | CMD python ./index.py 725 | ``` 726 | > - `FROM python:3-alpine3.15`: Specifies the base image to use for the build. In this case, it's `python:3-alpine3.15`, which is a lightweight Python 3 image based on Alpine Linux. 727 | > - `WORKDIR /app`: Sets the working directory for the build to `/app`. All subsequent commands will be run from this directory. 728 | > - `COPY . /app`: Copies the contents of the current directory (i.e., the directory containing the Dockerfile) into the `/app` directory in the image. 729 | > - `RUN pip install -r requirements.txt`: Runs the command `pip install -r requirements.txt` to install the dependencies specified in `requirements.txt`. 730 | > - `EXPOSE 5000`: Informs Docker that the container will listen on port 5000 at runtime. 731 | > - `CMD python ./index.py`: Sets the default command to run when the container starts to `python ./index.py`. 732 | - Step 3: Open the `index.py` file and paste the following code in it. 733 | ```python 734 | from flask import Flask 735 | helloworld = Flask(__name__) 736 | 737 | @helloworld.route("/") 738 | def run(): 739 | return "{ \"message\": \"Hey there I am Subham\" }" 740 | 741 | if __name__ == "__main__": 742 | helloworld.run(host="0.0.0.0", port=int("5000"), debug=True) 743 | ``` 744 | > - This is a simple flask app. It will return a json object when you visit the localhost:5000. 745 | > - Don't worry if you don't understand the code. If you really want to learn flask , then you can think of it as of now assume that it is a simple flask app that returns a json object or hello world type of thing. 746 | - Step 4: Open the `requirements.txt` file and paste the following code in it. 747 | ```bash 748 | Flask==2.2.3 749 | ``` 750 | - Step 5: Now open the terminal and go to the `first project` folder and run the following command. 751 | #### ⚡ Build the docker image 752 | ```bash 753 | docker build -t subham4041/first-flask-app:0.0.1.RELEASE . 754 | ``` 755 | > - `docker build -t`: This command is used to build the docker image. 756 | > - `subham4041/first-flask-app`: This is the name of the docker image. here `subham4041` is my docker hub username and `first-flask-app` is the name of the docker image. 757 | > - `0.0.1.RELEASE`: This is the version of the docker image you can change it to whatever you want. 758 | > - `.`: This is the path of the dockerfile. In this case, it is the current directory. 759 | 760 | > You can see the docker image in the docker desktop. 761 | 762 | ![image](https://user-images.githubusercontent.com/97989643/233201950-37c583da-1863-48e1-b1f0-040d38d066b6.png) 763 | 764 | #### ⚡ Run the docker image 765 | 766 | - Step 6: Now run the following command to check if the docker image is working or not. 767 | ```bash 768 | docker run -d -p 5000:5000 subham4041/first-flask-app:0.0.1.RELEASE 769 | ``` 770 | > You will see the something like this `9ff963bcb47695be360e0974224604dcd46782b8606.........` 771 | > you can check using `docker ps` command. 772 | 773 | - Step 7: Now visit the `localhost:5000` and you will see the following output. 774 | ```json 775 | { 776 | "message": "Hey there I am Subham" 777 | } 778 | ``` 779 | 780 | ![image](https://user-images.githubusercontent.com/97989643/233333329-f29c7b48-7604-428c-8247-392fb7772dbf.png) 781 | 782 | #### ⚡ Stop the docker container 783 | 784 | - Step 8: Now stop the docker container using the following command. 785 | ```bash 786 | docker container stop 684dfe64fad50af65280f603f5........... 787 | ``` 788 | or 789 | ```bash 790 | docker container stop 9ff 791 | ``` 792 | > - No need to write the full container id. You can write the first 3-4 characters of the container id. 793 | > - `docker container stop`: This command is used to stop the docker container and you can see the container id in the terminal. 794 | 795 | #### ⚡ Mapping the port 796 | - Step 9: While it is not possible to change the main port of a Docker container, you can map a port on your local machine to the container’s port. 797 | ```bash 798 | docker run -d -p 8000:5000 subham4041/first-flask-app:0.0.1.RELEASE 799 | ``` 800 | > - `docker run -d -p 8000:5000`: This command is used to map the port 8000 of the local machine to the port 5000 of the docker container. 801 | > - `subham4041/first-flask-app:0.0.1.RELEASE`: This is the name of the docker image. 802 | > - Now visit the `localhost:8000` and you will see the following output. 803 | ```json 804 | { 805 | "message": "Hey there I am Subham" 806 | } 807 | ``` 808 | - Step 10: Now stop the docker container using the following command. 809 | ```bash 810 | docker container stop 684 811 | ``` 812 | > - No need to write the full container id. You can write the first 3-4 characters of the container id. 813 | 814 | - Step 11: Let's push the docker image to the docker hub. 815 | 816 | #### ⚡ Push the docker image to the docker hub 817 | ```bash 818 | docker push subham4041/first-flask-app:0.0.1.RELEASE 819 | ``` 820 | ![image](https://user-images.githubusercontent.com/97989643/233347173-97fa283e-bb92-4b6f-a4a4-0a13ef4c47e0.png) 821 | 822 | 823 | 824 | ## Our Second Project with Docker 🚀 825 | Our second project is a simple nodejs app that returns a json object. 826 | #### ⚡ Nodejs Setup 827 | > Install nodejs in your system you can download it from [here](https://nodejs.org/en/download/). 828 | 829 | If you don't have any idea about nodejs don't worry this is a simple demo app so there is no need to understand the code in detail. We will completely focus on how docker works. If you know nodejs then you can easily understand the code also. 830 | 831 | - Step 1: Create a new folder and name it `second project`. 832 | - Step 2: Open the terminal and go to the `second project` folder and run the following command. 833 | ```bash 834 | npm init -y 835 | ``` 836 | > Basically, this command will create a `package.json` file where all the dependencies will be stored. 837 | 838 | - Step 3: Now just replace the `script` inside the `package.json` file with the following code. 839 | ```json 840 | "scripts": { 841 | "start": "node index.js" 842 | }, 843 | ``` 844 | ![image](https://user-images.githubusercontent.com/97989643/233415747-164334e1-675e-4ef2-a9d5-e0095359323e.png) 845 | 846 | Let me explain what does it mean. 847 | > - `scripts`: This is the key in the `package.json` file. 848 | > - `start`: This is the name of the script. 849 | > - `node index.js`: This is the command that will run when we run the `npm start` command. 850 | > - So basically, when we run the `npm start` command it will run the `node index.js` command. 851 | > - node is a javascript runtime environment. It is used to run javascript code outside the browser. 852 | > - `index.js`: This is the name of the file where we will write our code and using the node environment we will run the code. 853 | 854 | - Step 4: Now just install the express module using the following command. 855 | ```bash 856 | npm install express 857 | ``` 858 | > - `npm install express`: This command is used to install the express module. 859 | > - `npm` is a package manager for the javascript runtime environment node. 860 | > - `express`: This is a nodejs framework. It is used to create a web application. 861 | > - You can see the `node_modules` folder in the `second project` folder. 862 | 863 | - Step 5: Now create a new file and name it `index.js` and paste the following code in it. 864 | ```js 865 | const express = require('express'); 866 | const app = express(); 867 | const port = 5000; 868 | 869 | app.get('/', (req, res) => { 870 | res.json({ message: 'Hello World!' }); 871 | }); 872 | 873 | app.listen(port, () => { 874 | console.log(`Example app listening at http://localhost:${port}`); 875 | }); 876 | 877 | ``` 878 | > No need to worry about the code. This is similar to the flask app we created in the first project. We are just returning a json object. 879 | > - `const express = require('express');`: This is used to import the express module. 880 | > - `const app = express();`: This is used to create an express app. 881 | > - `const port = 5000;`: This is the port number of the app. 882 | > - `app.get('/', (req, res) => {`: This is the route of the app. Whenever we visit the `localhost:5000` it will return the json object. 883 | > - `res.json({ message: 'Hello World!' });`: This is used to return the json object similar to the flask app. 884 | > - `app.listen(port, () => {`: This is used to start the app. 885 | > - `console.log(`Example app listening at http://localhost:${port}`);`: This is used to print the message in the terminal. 886 | 887 | - Step 6: Now run the following command to start the app. 888 | ```bash 889 | npm start 890 | ``` 891 | hit this in the terminal and you will see the following output. 892 | ```bash 893 | Example app listening at http://localhost:5000 894 | ``` 895 | Now visit the `localhost:5000` and you will see the following output. 896 | ```json 897 | { 898 | "message": "Hello World!" 899 | } 900 | ``` 901 | ![image](https://user-images.githubusercontent.com/97989643/233419825-0a7c8dcb-75d9-42aa-9536-41148b23c591.png) 902 | 903 | #### ⚡ Login to the docker hub 904 | First, you need to login to the docker hub using the following command. 905 | ```bash 906 | docker login 907 | ``` 908 | You will see the following output. 909 | ```bash 910 | Logging in with your password grants your terminal complete access to your account. 911 | ``` 912 | - Step 7: Now stop the app using the `ctrl+c` command then delete the `node_modules` folder and create a new file and name it `Dockerfile` and paste the following code in it. 913 | ```dockerfile 914 | FROM node:14.17.0-alpine3.13 915 | WORKDIR /app 916 | COPY . /app 917 | RUN npm install 918 | EXPOSE 5000 919 | CMD node index.js 920 | ``` 921 | 922 | - Step 8: Now run the following command to build the docker image. 923 | ```bash 924 | docker build -t subham4041/second-node-app:0.0.1.RELEASE . 925 | ``` 926 | > - `docker build -t subham4041/second-node-app:0.0.1.RELEASE .`: This command is used to build the docker image. 927 | > - `docker build`: This is the command to build the docker image. 928 | > - `-t subham4041/second-node-app:0.0.1.RELEASE`: This is the name of the docker image. 929 | > - `subham4041`: This is the docker hub username. You will get this when you log in to the docker hub. 930 | > - `second-node-app`: This is the name of the docker image. 931 | > - `0.0.1.RELEASE`: This is the version of the docker image. 932 | > - `.`: This is the path of the dockerfile. In our case, it is the current directory. 933 | 934 | now you will see something like this. 935 | ![image](https://user-images.githubusercontent.com/97989643/233451193-e20a6b06-e37c-418a-a553-7cf82f8451e5.png) 936 | 937 | - Step 9: Now check how many docker images running in your system using the following command. 938 | ```bash 939 | docker ls 940 | ``` 941 | You will see the following output. 942 | ```bash 943 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 944 | ``` 945 | > - `CONTAINER ID`: This is the id of the container. 946 | > - `IMAGE`: This is the name of the docker image. 947 | > - `COMMAND`: This is the command that is running inside the container. 948 | > - `CREATED`: This is the time when the container was created. 949 | > - `STATUS`: This is the status of the container. 950 | > - `PORTS`: This is the port number of the container. 951 | > - `NAMES`: This is the name of the container. 952 | > - You can see that there is no docker image running in your system. 953 | - Step 10: Now run the following command to run the docker image. 954 | ```bash 955 | docker run -d -p 5001:5000 subham4041/second-node-app:0.0.1.RELEASE 956 | ``` 957 | 958 | > - `docker run -d -p 5001:5000 subham4041/second-node-app:0.0.1.RELEASE`: This command is used to run the docker image. 959 | > - `docker run`: This is the command to run the docker image. 960 | > - `-d`: This is used to run the docker image in the background. 961 | > - `-p 5001:5000`: This is used to map the port number of the docker image to the port number of the host machine. 962 | > - `subham4041/second-node-app:0.0.1.RELEASE`: This is the name of the docker image. 963 | > - You can see that the docker image is running in the background. 964 | 965 | - Step 11: Now check how many docker images running in your system using the following command. 966 | ```bash 967 | docker ps 968 | ``` 969 | You will see the following output. 970 | ```bash 971 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 972 | b3b0b5b5b9b0 subham4041/second-node-app:0.0.1.RELEASE "docker-entrypoint.s…" 10 seconds ago Up 9 seconds 973 | ``` 974 | 975 | - Step 12: Now visit the `localhost:5001` and you will see the following output. 976 | ```json 977 | { 978 | "message": "Hello World!" 979 | } 980 | ``` 981 | - Step 13: Now run the following command to push the docker image to the docker hub. 982 | ```bash 983 | docker push subham4041/second-node-app:0.0.1.RELEASE 984 | ``` 985 | ![image](https://user-images.githubusercontent.com/97989643/233453706-e185ecb4-b886-4216-b551-64bc51062eda.png) 986 | 987 | - Step 14: Now let's delete the docker image from the local system using the following command. 988 | 989 | > You can do this using the docker desktop app also. 990 | 991 | #### ⚡ Check the container id 992 | First, you need to check the image id using the following command. 993 | ```bash 994 | docker ps 995 | ``` 996 | #### ⚡ Stop the container 997 | Now run the following command to stop the container. 998 | ```bash 999 | docker stop 1000 | ``` 1001 | > In my case, the container id is `b3b0b5b5b9b0` so I will run the following command `docker stop b3b0b5b5b9b0`. 1002 | 1003 | #### ⚡ Kill the container 1004 | Now run the following command to kill the container. 1005 | ```bash 1006 | docker kill 1007 | ``` 1008 | > This will send a signal to the container to gracefully stop. If you want to forcefully stop the container immediately, you can use the docker kill command instead:`docker stop ` 1009 | 1010 | #### ⚡ Remove the container 1011 | You can remove the container using the `docker rm` command followed by the container ID. For example, to remove the container with ID `b9061e6d08b6`, you can use the following command: 1012 | ```bash 1013 | docker rm b9061e6d08b6 1014 | ``` 1015 | #### ⚡ Remove the image 1016 | After removing the container, you can then delete the image using the `docker rmi` command: 1017 | ```bash 1018 | docker rmi 1019 | ``` 1020 | > In my case, the image id is `a0dacd3ecd79e1252ca8e8a655902af1b6ae98ee609cdee91056c67a6ca00a5c` so I will run the following command `docker rmi a0dacd3ecd79e1252ca8e8a655902af1b6ae98ee609cdee91056c67a6ca00a5c`. 1021 | > This will delete the image from your system. 1022 | 1023 | - Step 15: Now run the following command to pull the docker image from the docker hub. 1024 | #### ⚡ Pull the docker image 1025 | 1026 | ```bash 1027 | docker pull subham4041/second-node-app:0.0.1.RELEASE 1028 | ``` 1029 | - Step 16: Now run the following command to run the docker image. 1030 | ```bash 1031 | docker run -d -p 5001:5000 subham4041/second-node-app:0.0.1.RELEASE 1032 | ``` 1033 | Now visit the `localhost:5001` and you will see the following output. 1034 | ```json 1035 | { 1036 | "message": "Hello World!" 1037 | } 1038 | ``` 1039 | 1040 | ## 🥰 What did we understand from these two projects? 1041 | 1042 | If someone pulls the docker image from the docker hub, then they don't need to install the nodejs and npm in their system. They just need to install the docker in their system and then they can run the docker image and they can easily access the application without installing the nodejs and npm in their system. This is the **magic of docker.** 1043 | 1044 | ## ✨ Docker CLI Cheat Sheet 1045 | 1046 | ### 1. Installation 1047 | 1048 | | Command | Meaning | Syntax | 1049 | | --- | --- | --- | 1050 | | For Windows | This command helps you to install Docker on Windows. | `https://download.docker.com/win/stable/InstallDocker.msi` | 1051 | | For Linux | This command helps you to install Docker on Linux. | `curl -sSL https://get.docker.com/ | sh` | 1052 | | For Mac | This command helps you to install Docker on Mac OS. | `https://download.docker.com/mac/stable/Docker.dmg` | 1053 | 1054 | ### 2. Docker Registry and Repository 1055 | 1056 | | Command | Meaning | Syntax | 1057 | | --- | --- | --- | 1058 | | Login to a Registry | This command helps you log in to your Registry. | `docker login [options] [server]` | 1059 | | Logout from a registry | This command helps you log out from your Registry. | `docker logout [server]` | 1060 | | Searching an image | By using this docker command you can search any image from your docker. | `docker search [options] term` | 1061 | | Pulling an image | This command can be used to download a specific image or set of images. | `docker pull [options] name[:tag]` | 1062 | | Pushing an image | This command can be used to push a specific image or set of images. | `docker push [options] name[:tag]` | 1063 | 1064 | ### 3. Running Containers 1065 | 1066 | | Command | Meaning | Syntax | 1067 | | --- | --- | --- | 1068 | | Running a container from an image | This command creates and starts a container from an image. You can specify various options such as ports, volumes, environment variables, etc. | `docker run [options] image[:tag] [command] [args]` | 1069 | | Listing running containers | This command shows all the containers that are currently running. You can use filters and format options to customize the output. | `docker ps [options]` | 1070 | | Listing all containers (running and stopped) | This command shows all the containers that exist on your system, regardless of their status. You can use filters and format options to customize the output. | `docker ps -a [options]` | 1071 | | Stopping a container | This command stops a running container by sending a SIGTERM signal and then a SIGKILL signal if the container does not stop within a grace period. You can specify multiple containers to stop at once. | `docker stop [options] container [container...]` | 1072 | | Starting a stopped container | This command starts a stopped container by restoring its state. You can specify multiple containers to start at once. | `docker start [options] container [container...]` | 1073 | | Restarting a container | This command restarts a running or stopped container by stopping and then starting it again. You can specify multiple containers to restart at once. | `docker restart [options] container [container...]` | 1074 | | Removing a container | This command removes one or more containers from your system. You can use filters and force options to remove containers that are running or have volumes attached to them. | `docker rm [options] container [container...]` | 1075 | 1076 | 1077 | ### 4. Managing Images 1078 | 1079 | | Command | Meaning | Syntax | 1080 | | --- | --- | --- | 1081 | | Building an image from a Dockerfile | This command builds an image from a Dockerfile and optionally tags it with a name and tag. You can specify various options such as build arguments, cache settings, etc. | `docker build [options] path` | 1082 | | Removing an image from your system | This command removes one or more images from your system. You can use filters and force options to remove images that are in use or have dependent images. | `docker rmi [options] image [image...]` | 1083 | | Tagging an image with a name and tag | This command assigns a name and tag to an image. You can use this to create aliases for images or to prepare them for pushing to a registry. | `docker tag [options] image[:tag] name[:tag]` | 1084 | | Saving an image to a tar archive | This command saves one or more images to a tar archive file. You can use this to backup or transfer images between systems. | `docker save [options] image [image...] -o file` | 1085 | | Loading an image from a tar archive | This command loads one or more images from a tar archive file. You can use this to restore or import images from a backup or another system. | `docker load [options] -i file` | 1086 | 1087 | ### 5. Managing Volumes 1088 | 1089 | | Command | Meaning | Syntax | 1090 | | --- | --- | --- | 1091 | | Creating a volume | This command creates a volume on your system. You can specify various options such as name, driver, labels, etc. | `docker volume create [options] [name]` | 1092 | | Listing volumes on your system | This command shows all the volumes that are stored on your system. You can use filters and format options to customize the output. | `docker volume ls [options]` | 1093 | | Inspecting a volume | This command shows detailed information about a specific volume. You can use this to check the status, driver, mount point, etc. of a volume. | `docker volume inspect [options] volume [volume...]` | 1094 | | Removing a volume from your system | This command removes one or more volumes from your system. You can use filters and force options to remove volumes that are in use or have dependent containers. | `docker volume rm [options] volume [volume...]` | 1095 | | Pruning unused volumes from your system | This command removes all the volumes that are not referenced by any containers from your system. You can use filters to exclude some volumes from pruning. | `docker volume prune [options]` | 1096 | 1097 | ### 6. Managing Networks 1098 | 1099 | | Command | Meaning | Syntax | 1100 | | --- | --- | --- | 1101 | | Creating a network | This command creates a network on your system. You can specify various options such as name, driver, subnet, etc. | `docker network create [options] [name]` | 1102 | | Listing networks on your system | This command shows all the networks that are available on your system. You can use filters and format options to customize the output. | `docker network ls [options]` | 1103 | | Inspecting a network | This command shows detailed information about a specific network. You can use this to check the status, driver, IP range, connected containers, etc. of a network. | `docker network inspect [options] network [network...]` | 1104 | | Removing a network from your system | This command removes one or more networks from your system. You can use filters and force options to remove networks that are in use or have dependent containers. | `docker network rm [options] network [network...]` | 1105 | | Pruning unused networks from your system | This command removes all the networks that are not used by any containers from your system. You can use filters to exclude some networks from pruning. | `docker network prune [options]` | 1106 | 1107 | ### 7. Miscellaneous Commands (continued) 1108 | 1109 | | Command | Meaning | Syntax | 1110 | | --- | --- | --- | 1111 | | Getting help on docker commands and options | This command shows the usage and options for any docker command or subcommand. You can use this to learn more about how to use docker. | `docker [command] --help` | 1112 | | Getting the version of docker | This command shows the version and build information of docker on your system. You can use this to check if you have the latest version or if you need to update. | `docker version [options]` | 1113 | | Getting system-wide information on docker | This command shows system-wide information about docker on your system. You can use this to check the status, resources, configuration, etc. of docker. | `docker info [options]` | 1114 | | Executing a command in a running container | This command executes a command in a running container and returns the output. You can use this to run commands that are not available in the container's shell or to interact with the container's processes. | `docker exec [options] container command [args]` | 1115 | | Attaching to a running container | This command attaches your terminal to a running container's standard input, output, and error streams. You can use this to interact with the container's shell or processes. | `docker attach [options] container` | 1116 | | Copying files or folders between a container and your system | This command copies files or folders between a container and your system. You can use this to transfer data to or from a container. | `docker cp [options] source destination` | 1117 | | Viewing logs from a container | This command shows the logs from a container's standard output and error streams. You can use this to monitor or troubleshoot a container's activity. | `docker logs [options] container` | 1118 | | Committing changes to an image | This command creates a new image from a container's changes. You can use this to save your modifications or to create new images based on existing ones. | `docker commit [options] container [repository[:tag]]` | 1119 | | Building an image from stdin or a URL | This command builds an image from a Dockerfile that is provided through stdin or a URL. You can use this to build images from remote sources or scripts. | `docker build [options] - < Dockerfile` or `docker build [options] url` | 1120 | | Showing the history of an image | This command shows the history of an image, including the layers and commands that were used to create it. You can use this to inspect how an image was built or to optimize it. | `docker history [options] image` | 1121 | 1122 | 1123 | ## 📌 Conclusion 1124 | 1125 | Congratulations! You have completed this tutorial on Docker and learned how to use it for various purposes. You have also created some amazing projects using Docker that showcase your skills and creativity. You should be proud of yourself! 1126 | 1127 | Now you can experiment with whatever you want with Docker and explore its endless possibilities. You can also improve this tutorial with a pull request or add more content if you have any suggestions or ideas. Your feedback is always welcome and appreciated. 1128 | 1129 | Thank you for reading this tutorial and following along. I hope you enjoyed it and learned something new. Happy Docking! 😊 1130 | --------------------------------------------------------------------------------