-
Notifications
You must be signed in to change notification settings - Fork 20
/
5-2.txt
99 lines (75 loc) · 1.71 KB
/
5-2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//terminal
// vi server.js
/* server.js
var express = require('express');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var User = require('./models/User');
var app = express();
app.use(bodyParser.json());
mongoUri = process.env.mongoUri
mongoose.connect(mongoUri);
app.get('/users', function(req, res) {
User.find({}, function(err, users) {
res.json(users);
});
});
app.post('/users', function(req,res) {
console.log('post /users');
var user = new User(req.body);
user.save(function(err, user) {
res.json(user);
});
});
var port = process.env.port || 3000;
app.listen(port, function() {
console.log('server started');
});
*/
//terminal
// cd models/
// vi User.js
/* models/User.js
var mongoose = require('mongoose');
var userSchema = mongoose.Schema({
name: String
});
module.exports = mongoose.model('User', userSchema);
*/
//terminal
// cd ..
// vi docker-compose.yml
/* docker-compose.yml
database:
image: mongo
api:
build: .
volumes:
- .:/usr/src/app
ports:
- "3000:80"
environment:
port: "80"
mongoUri: "mongodb://database/app-dev"
links:
- database
*/
//terminal
// docker-compose up -d
// curl http://localhost:3000/users
// curl -H "Content-Type: application/json" -X POST -d '{"name": "john"}' http://localhost:3000/users
// curl http://localhost:3000/users
// curl -H "Content-Type: application/json" -X POST -d '{"name": "mary"}' http://localhost:3000/users
// curl http://localhost:3000/users
// docker ps
// docker exec -it service_api_1 /bin/bash
// cat /etc/hosts
// exit
// docker-compose stop
// docker-compose up -d
// curl http://localhost:3000/users
// docker ps
// docker inspect service_database_1 | less
// /Volumes
// vi docker-compose.yml
//