Skip to content

Commit 304f071

Browse files
committed
tweaks part2
1 parent 1814b0f commit 304f071

3 files changed

Lines changed: 46 additions & 42 deletions

File tree

‎docs/getting-started.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The course is suitable for anyone interested in Docker or containerization and h
2323
The 2024 edition of the course starts officially on 11th March. The material is currently being updated. At the time of writing (11th March) the following parts have already been updated
2424

2525
- Part 1
26-
- Part 2 up to and including chapter _Docker networking_
26+
- Part 2
2727

2828
You may continue already beyond the updated material but beware, there might be some outdated content!
2929

‎docs/part-2/section-3.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ There is again a button (and a form!) in the frontend that you can use to ensure
252252

253253
Submit the docker-compose.yml
254254

255-
* TIP: When configuring the database, you might need to destroy the automatically created volumes. Use commands `docker volume prune`, `docker volume ls` and `docker volume rm` to remove unused volumes when testing. Make sure to remove containers that depend on them beforehand.
256-
255+
TIPS:
256+
* When configuring the database, you might need to destroy the automatically created volumes. Use commands `docker volume prune`, `docker volume ls` and `docker volume rm` to remove unused volumes when testing. Make sure to remove containers that depend on them beforehand.
257257
* `restart: unless-stopped` can help if the Postgres takes a while to get ready
258258

259259
![Backend, frontend, redis and a database](/img/exercises/back-front-redis-and-database.png)
@@ -291,9 +291,9 @@ It might be Nginx configuration problem. Ensure there is a trailing / on the bac
291291

292292
:::info Exercise 2.8
293293

294-
Add [Nginx](https://hub.docker.com/_/nginx) to the example to work as a [reverse proxy](https://en.wikipedia.org/wiki/Reverse_proxy) in front of the example app frontend and backend. According to Wikipedia
294+
In this exercise, you shall add [Nginx](https://hub.docker.com/_/nginx) to work as a [reverse proxy](https://en.wikipedia.org/wiki/Reverse_proxy) in front of the example app frontend and backend.
295295

296-
_A reverse proxy is a type of proxy server that retrieves resources on behalf of a client from one or more servers. These resources are then returned to the client, appearing as if they originated from the reverse proxy server itself._
296+
According to Wikipedia _a reverse proxy is a type of proxy server that retrieves resources on behalf of a client from one or more servers. These resources are then returned to the client, appearing as if they originated from the reverse proxy server itself._
297297

298298
![Backend, frontend, redis, a database and nginx](/img/exercises/back-front-redis-database-and-nginx.png)
299299

@@ -303,7 +303,7 @@ The idea is that a browser makes _all_ requests to _http://localhost_. If the re
303303

304304
So, at the end, you should see that the frontend is accessible simply by going to <http://localhost>. All buttons, except the one labeled _Exercise 2.8_ may have stopped working, do not worry about them, we shall fix that later.
305305

306-
The following file should be set to _/etc/nginx/nginx.conf_ inside the nginx container. You can use a file bind mount where the contents of the file is the following:
306+
The following file should be set to _/etc/nginx/nginx.conf_ inside the Nginx container. You can use a file bind mount where the contents of the file is the following:
307307

308308
```bash
309309
events { worker_connections 1024; }

‎docs/part-2/section-4.md‎

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
title: 'Containers in development'
33
---
44

5-
Containers are not only great in production. They can be used in development environments as well and offer a number of benefits. The same _works-on-my-machine_ problem is faced often when a new developer joins the team. Not to mention the headache of switching runtime versions or a local database!
5+
Containers are not only great in production. They can be used in development environments as well and offer several benefits. The same _works-on-my-machine_ problem is faced often when a new developer joins the team. Not to mention the headache of switching runtime versions or a local database!
66

7-
For an example, a [software development team](https://toska.dev/) at the University of Helsinki has a fully [containerized development environment](https://ethesis.helsinki.fi/repository/handle/123456789/30995). The principle in all development projects is to have a setup so that a new developer only needs to install Docker and clone the project code from GitHub to get started. Not a single dependency is ever installed on to host machine, Git, Docker and the text editor of choice is only thing that is needed.
7+
For example, a [software development team](https://toska.dev/) at the University of Helsinki has a fully [containerized development environment](https://ethesis.helsinki.fi/repository/handle/123456789/30995). The principle in all development projects is to have a setup so that a new developer only needs to install Docker and clone the project code from GitHub to get started. Not a single dependency is ever installed on to host machine, Git, Docker and the text editor of choice are the only things that are needed.
88

9-
Even if your application is not completely containerized during development, containers can very helpful. For example, say you need MongoDB version 4.0.22 installed in port 5656. It's now a oneliner: "docker run -p 5656:27017 mongo:4.0.22" (MongoDB uses 27017 as default port).
9+
Even if your application is not completely containerized during development, containers can be very helpful. For example, say you need MongoDB version 4.0.22 installed in port 5656. It's now an oneliner: "docker run -p 5656:27017 mongo:4.0.22" (MongoDB uses 27017 as the default port).
1010

1111
Let's containerize a NodeJS development environment. As you perhaps know [NodeJS](https://nodejs.org/en/) is a cross-platform JavaScript runtime that makes it possible to run JavaScript in your machine, servers and embedded devices, among many other platforms
1212

13-
The setup requires some expertise on the way how NodeJS works. Here is a simplified explanation if you're not familiar: libraries are defined in `package.json` and `package-lock.json` and installed with `npm install`. [npm](https://www.npmjs.com/) is the Node package manager.
13+
The setup requires some expertise in the way how NodeJS works. Here is a simplified explanation if you're not familiar: libraries are defined in `package.json` and `package-lock.json` and installed with `npm install`. [npm](https://www.npmjs.com/) is the Node package manager.
1414

15-
To run application with the packages we have script defined in package.json that instructs Node to execute index.js, the main/entry file in this case the script is executed with `npm start`. The application already includes code to watch for changes in the filesystem and restart the application if any changes are detected.
15+
To run the application with the packages we have a script defined in package.json that instructs Node to execute index.js, the main/entry file in this case the script is executed with `npm start`. The application already includes code to watch for changes in the filesystem and restart the application if any changes are detected.
1616

17-
The project "node-dev-env" is here [https://github.com/docker-hy/material-applications/tree/main/node-dev-env](https://github.com/docker-hy/material-applications/tree/main/node-dev-env). I already included a development Dockerfile and a helpful docker-compose.yml.
17+
The project "node-dev-env" is here [https://github.com/docker-hy/material-applications/tree/main/node-dev-env](https://github.com/docker-hy/material-applications/tree/main/node-dev-env). We have already included a development Dockerfile and a helpful docker-compose.yml.
1818

1919
**Dockerfile**
2020
```Dockerfile
@@ -50,46 +50,49 @@ And that's it. We'll use volume to copy all source code inside the volume so CMD
5050
5151
```console
5252
$ docker compose up
53-
Creating network "node-dev-env_default" with the default driver
54-
Creating volume "node-dev-env_node_modules" with default driver
55-
Building node-dev-env
56-
Step 1/4 : FROM node:14
57-
...
5853

59-
Attaching to node-dev-env
60-
node-dev-env |
61-
node-dev-env | > dev-env@1.0.0 start /usr/src/app
62-
node-dev-env | > nodemon index.js
6354
...
6455

65-
node-dev-env | App listening in port 3000
56+
Attaching to node-dev-env
57+
node-dev-env |
58+
node-dev-env | > dev-env@1.0.0 start
59+
node-dev-env | > nodemon index.js
60+
node-dev-env |
61+
node-dev-env | [nodemon] 2.0.7
62+
node-dev-env | [nodemon] to restart at any time, enter `rs`
63+
node-dev-env | [nodemon] watching path(s): *.*
64+
node-dev-env | [nodemon] watching extensions: js,mjs,json
65+
node-dev-env | [nodemon] starting `node index.js`
66+
node-dev-env | App listening in port 3000
6667
```
6768

68-
Great! The initial start up is a bit slow. It is a lot faster now that the image is already built. We can rebuild the whole environment whenever we want with `docker compose up --build`.
69+
Great! The initial start-up is a bit slow. It is a lot faster now that the image is already built. We can rebuild the whole environment whenever we want with `docker compose up --build`.
6970

70-
Let's see if the application works. Use browser to access [http://localhost:3000](http://localhost:3000), it should do a simple plus calculation with the query params.
71+
Let's see if the application works. Use the browser to access [http://localhost:3000](http://localhost:3000), it should do a simple plus calculation with the query params.
7172

72-
However, the calulation doesn't make sense! Let's fix the bug. I bet it's this line right here [https://github.com/docker-hy/material-applications/blob/main/node-dev-env/index.js#L5](https://github.com/docker-hy/material-applications/blob/main/node-dev-env/index.js#L5)
73+
However, the calculation doesn't make sense! Let's fix the bug. I bet it's this line right here [https://github.com/docker-hy/material-applications/blob/main/node-dev-env/index.js#L5](https://github.com/docker-hy/material-applications/blob/main/node-dev-env/index.js#L5)
7374

7475
When I change the line, on my host machine the application instantly notices that files have changed:
7576

7677
```console
77-
▶ docker compose up
78-
Starting node-dev-env ... done
78+
$ docker compose up
79+
80+
...
81+
7982
Attaching to node-dev-env
80-
node-dev-env |
81-
node-dev-env | > dev-env@1.0.0 start /usr/src/app
82-
node-dev-env | > nodemon index.js
83-
node-dev-env |
84-
node-dev-env | [nodemon] 2.0.7
85-
node-dev-env | [nodemon] to restart at any time, enter `rs`
86-
node-dev-env | [nodemon] watching path(s): *.*
87-
node-dev-env | [nodemon] watching extensions: js,mjs,json
88-
node-dev-env | [nodemon] starting `node index.js`
89-
node-dev-env | App listening in port 3000
90-
node-dev-env | [nodemon] restarting due to changes...
91-
node-dev-env | [nodemon] starting `node index.js`
92-
node-dev-env | App listening in port 3000
83+
node-dev-env |
84+
node-dev-env | > dev-env@1.0.0 start
85+
node-dev-env | > nodemon index.js
86+
node-dev-env |
87+
node-dev-env | [nodemon] 2.0.7
88+
node-dev-env | [nodemon] to restart at any time, enter `rs`
89+
node-dev-env | [nodemon] watching path(s): *.*
90+
node-dev-env | [nodemon] watching extensions: js,mjs,json
91+
node-dev-env | [nodemon] starting `node index.js`
92+
node-dev-env | App listening in port 3000
93+
node-dev-env | [nodemon] restarting due to changes...
94+
node-dev-env | [nodemon] starting `node index.js`
95+
node-dev-env | App listening in port 3000
9396
```
9497

9598
And now a page refresh shows that our code change fixed the issue. The development environment works.
@@ -98,11 +101,12 @@ The next exercise can be extremely easy or extremely hard. Feel free to have fun
98101

99102
## Exercise 2.11
100103

101-
102104
:::info Exercise 2.11
103105

104106
Select some of your own development projects and start utilizing containers in the development environment.
105107

106-
Explain what you have done. It can be anything, e.g., a support for docker-compose.yml to have services (such as databases) containerized or even a fully blown containerized development environment.
108+
Explain what you have done. It can be anything, e.g., support for docker-compose.yml to have services (such as databases) containerized or even a fully blown containerized development environment.
107109

108110
:::
111+
112+
If you are interested in how to build a containerized development environment for a React/Node Single page web app, please have a look at the course [Full stack open](https://fullstackopen.com) which has one [chapter](https://fullstackopen.com/en/part12/basics_of_orchestration#development-in-containers) devoted to the topic.

0 commit comments

Comments
 (0)