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