Skip to content

Commit ed76440

Browse files
committed
Update code/packages
1 parent 818d4ca commit ed76440

9 files changed

Lines changed: 3243 additions & 1972 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ Interested in learning more about Docker? Visit https://www.pluralsight.com/cour
77

88
### Starting the Application with Docker Containers:
99

10-
1. Install Docker for Windows or Docker for Mac (If you're on Windows 7 install Docker Toolbox: http://docker.com/toolbox).
10+
1. Install [Docker Desktop](https://docker.com/get-started)
1111

1212
2. Open a command prompt.
1313

1414
3. Run the commands listed in `node.dockerfile` (see the comments at the top of the file).
1515

16-
4. Navigate to http://localhost:3000. Use http://192.168.99.100:8080 in your browser to view the site if using Docker toolbox. This assumes that's the IP assigned to VirtualBox - change if needed.
16+
4. Navigate to http://localhost:3000.
1717

1818

1919
### Starting the Application with Docker Compose

lib/dataSeeder.js

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,49 @@
1-
'use strict';
2-
3-
var DockerCommand = require('../models/dockerCommand');
1+
const DockerCommand = require('../models/dockerCommand');
42

53
var dataInitializer = function () {
64

7-
var initializeData = function(callback) {
8-
9-
var runDockerCommand = new DockerCommand({
10-
command : 'run',
11-
description : 'Runs a Docker container',
12-
examples : [
13-
{
14-
example: 'docker run imageName',
15-
description: 'Creates a running container from the image. Pulls it from Docker Hub if the image is not local'
16-
},
17-
{
18-
example: 'docker run -d -p 8080:3000 imageName',
19-
description: 'Runs a container in "detached" mode with an external port of 8080 and a container port of 3000.'
20-
}
21-
]});
22-
23-
runDockerCommand.save(function(err) {
24-
if (err) {
25-
return callback(err);
26-
}
27-
});
28-
29-
var psDockerCommand = new DockerCommand({
30-
command : 'ps',
31-
description : 'Lists containers',
32-
examples : [
33-
{
34-
example: 'docker ps',
35-
description: 'Lists all running containers'
36-
},
37-
{
38-
example: 'docker ps -a',
39-
description: 'Lists all containers (even if they are not running)'
40-
}
41-
]});
42-
43-
psDockerCommand.save(function(err) {
44-
if (err) {
45-
return callback(err);
46-
}
47-
});
48-
49-
callback();
50-
51-
};
5+
const initializeData = async (callback) => {
6+
7+
const runDockerCommand = new DockerCommand({
8+
command: 'run',
9+
description: 'Runs a Docker container',
10+
examples: [
11+
{
12+
example: 'docker run imageName',
13+
description: 'Creates a running container from the image. Pulls it from Docker Hub if the image is not local'
14+
},
15+
{
16+
example: 'docker run -d -p 8080:3000 imageName',
17+
description: 'Runs a container in "detached" mode with an external port of 8080 and a container port of 3000.'
18+
}
19+
]
20+
});
21+
22+
const psDockerCommand = new DockerCommand({
23+
command: 'ps',
24+
description: 'Lists containers',
25+
examples: [
26+
{
27+
example: 'docker ps',
28+
description: 'Lists all running containers'
29+
},
30+
{
31+
example: 'docker ps -a',
32+
description: 'Lists all containers (even if they are not running)'
33+
}
34+
]
35+
});
36+
37+
38+
try {
39+
await runDockerCommand.save();
40+
await psDockerCommand.save();
41+
callback();
42+
} catch (err) {
43+
callback(err);
44+
}
45+
46+
};
5247

5348

5449
return {

lib/database.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ var mongoose = require('mongoose');
44
var database = function () {
55
var conn = null,
66

7-
init = function (config) {
7+
init = (config) => {
88
console.log('Trying to connect to ' + config.host + '/' + config.database + ' MongoDB database');
99
var options = {
10-
promiseLibrary: global.Promise,
1110
useNewUrlParser: true,
1211
useUnifiedTopology: true
1312
};
@@ -16,15 +15,13 @@ var database = function () {
1615
mongoose.connect(connString, options);
1716
conn = mongoose.connection;
1817
conn.on('error', console.error.bind(console, 'connection error:'));
19-
conn.once('open', function() {
20-
console.log('db connection open');
21-
});
18+
conn.once('open', () => console.log('db connection open'));
2219
return conn;
2320
},
2421

25-
close = function() {
22+
close = () => {
2623
if (conn) {
27-
conn.close(function () {
24+
conn.close(() => {
2825
console.log('Mongoose default connection disconnected through app termination');
2926
process.exit(0);
3027
});

lib/dockerCommandsRepository.js

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
1-
'use strict';
2-
3-
var DockerCommand = require('../models/dockerCommand');
4-
5-
var dockerCommandsRepository = function() {
6-
7-
var getDockerCommands = function(callback) {
8-
9-
DockerCommand.find(function(err, commands) {
10-
11-
if (err) return callback(err, null);
12-
13-
callback(err, commands);
14-
15-
});
16-
17-
};
18-
19-
return {
20-
getDockerCommands : getDockerCommands
21-
};
22-
23-
}();
24-
25-
module.exports = dockerCommandsRepository;
1+
const DockerCommand = require('../models/dockerCommand');
2+
3+
const getDockerCommands = async () => {
4+
try {
5+
const commands = await DockerCommand.find();
6+
return commands;
7+
}
8+
catch (err)
9+
{
10+
return [];
11+
}
12+
};
13+
14+
module.exports = getDockerCommands;

node.dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
# Build: docker build -f node.dockerfile -t danwahlin/nodeapp .
1+
# Build: docker build -f node.dockerfile -t nodeapp .
22

33
# Option 1: Create a custom bridge network and add containers into it
44

55
# docker network create --driver bridge isolated_network
66
# docker run -d --net=isolated_network --name mongodb mongo
77

8-
# NOTE: $(pwd) in the following line is for Mac and Linux. See https://blog.codewithdan.com/docker-volumes-and-print-working-directory-pwd/ for Windows examples.
9-
# docker run -d --net=isolated_network --name nodeapp -p 3000:3000 -v $(pwd)/logs:/var/www/logs danwahlin/nodeapp
8+
# NOTE: $(pwd) in the following line is for Mac and Linux. Use ${PWD} for Powershell.
9+
# See https://blog.codewithdan.com/docker-volumes-and-print-working-directory-pwd/ syntax examples.
10+
# docker run -d --net=isolated_network --name nodeapp -p 3000:3000 -v $(pwd)/logs:/var/www/logs nodeapp
1011

1112
# Seed the database with sample database
1213
# Run: docker exec nodeapp node dbSeeder.js
@@ -27,7 +28,7 @@ ENV TERM xterm
2728
RUN apk update && apk add $PACKAGES
2829

2930
WORKDIR /var/www
30-
COPY package.json package-lock.json ./
31+
COPY package*.json ./
3132
RUN npm install
3233

3334
COPY . ./

0 commit comments

Comments
 (0)