Studying docker

initial commit

+172
+13
first-demo-starting-setup/Dockerfile
··· 1 + FROM node:14 2 + 3 + WORKDIR /app 4 + 5 + COPY package.json . 6 + 7 + RUN npm install 8 + 9 + COPY . . 10 + 11 + EXPOSE 3000 12 + 13 + CMD [ "node", "app.mjs" ]
+13
first-demo-starting-setup/app.mjs
··· 1 + import express from 'express'; 2 + 3 + import connectToDatabase from './helpers.mjs' 4 + 5 + const app = express(); 6 + 7 + app.get('/', (req, res) => { 8 + res.send('<h2>Hi there!</h2>'); 9 + }); 10 + 11 + await connectToDatabase(); 12 + 13 + app.listen(3000);
+11
first-demo-starting-setup/helpers.mjs
··· 1 + const connectToDatabase = () => { 2 + const dummyPromise = new Promise((resolve, reject) => { 3 + setTimeout(() => { 4 + resolve(); 5 + }, 1000); 6 + }); 7 + 8 + return dummyPromise; 9 + }; 10 + 11 + export default connectToDatabase;
+18
first-demo-starting-setup/package.json
··· 1 + { 2 + "name": "docker-complete", 3 + "version": "1.0.0", 4 + "description": "", 5 + "main": "index.js", 6 + "scripts": { 7 + "test": "echo \"Error: no test specified\" && exit 1" 8 + }, 9 + "repository": { 10 + "type": "git", 11 + "url": "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/docker-complete-guide" 12 + }, 13 + "author": "", 14 + "license": "ISC", 15 + "dependencies": { 16 + "express": "^4.17.1" 17 + } 18 + }
+11
nodejs-first-starting/Dockerfile
··· 1 + FROM node 2 + 3 + WORKDIR /app 4 + 5 + COPY . /app 6 + 7 + RUN npm install 8 + 9 + EXPOSE 80 10 + 11 + CMD ["node","server.js"]
+12
nodejs-first-starting/package.json
··· 1 + { 2 + "name": "docker-complete", 3 + "version": "1.0.0", 4 + "description": "", 5 + "main": "server.js", 6 + "author": "Maximilian Schwarzmüller / Academind GmbH", 7 + "license": "MIT", 8 + "dependencies": { 9 + "express": "^4.17.1", 10 + "body-parser": "1.19.0" 11 + } 12 + }
+48
nodejs-first-starting/public/styles.css
··· 1 + html { 2 + font-family: sans-serif; 3 + } 4 + 5 + body { 6 + margin: 0; 7 + } 8 + 9 + section, 10 + form { 11 + padding: 1rem; 12 + border-radius: 12px; 13 + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26); 14 + margin: 2rem auto; 15 + max-width: 40rem; 16 + } 17 + 18 + .form-control { 19 + margin: 0.5rem 0; 20 + } 21 + 22 + input { 23 + font: inherit; 24 + } 25 + 26 + input, 27 + label { 28 + display: block; 29 + } 30 + 31 + label { 32 + font-weight: bold; 33 + margin-bottom: 0.5rem; 34 + } 35 + 36 + button { 37 + background-color: #2f005a; 38 + border: 1px solid #2f005a; 39 + color: white; 40 + cursor: pointer; 41 + padding: 0.5rem 1.5rem; 42 + } 43 + 44 + button:hover, 45 + button:active { 46 + background-color: #50005a; 47 + border-color: #50005a; 48 + }
+46
nodejs-first-starting/server.js
··· 1 + const express = require('express'); 2 + const bodyParser = require('body-parser'); 3 + 4 + const app = express(); 5 + 6 + let userGoal = 'Learn Docker!'; 7 + 8 + app.use( 9 + bodyParser.urlencoded({ 10 + extended: false, 11 + }) 12 + ); 13 + 14 + app.use(express.static('public')); 15 + 16 + app.get('/', (req, res) => { 17 + res.send(` 18 + <html> 19 + <head> 20 + <link rel="stylesheet" href="styles.css"> 21 + </head> 22 + <body> 23 + <section> 24 + <h2>My Course Goal</h2> 25 + <h3>${userGoal}</h3> 26 + </section> 27 + <form action="/store-goal" method="POST"> 28 + <div class="form-control"> 29 + <label>Course Goal</label> 30 + <input type="text" name="goal"> 31 + </div> 32 + <button>Set Course Goal</button> 33 + </form> 34 + </body> 35 + </html> 36 + `); 37 + }); 38 + 39 + app.post('/store-goal', (req, res) => { 40 + const enteredGoal = req.body.goal; 41 + console.log(enteredGoal); 42 + userGoal = enteredGoal; 43 + res.redirect('/'); 44 + }); 45 + 46 + app.listen(80);