Skip to content

Commit cac4404

Browse files
committed
Fixes after proofreading
1 parent d70564b commit cac4404

File tree

6 files changed

+76
-75
lines changed

6 files changed

+76
-75
lines changed

Deploy/Containerization/backend_dockerfile/task.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
Before we write the Dockerfile for the backend, we have made a few changes
2-
to the project that will simplify our work later on. Please take a look at them.
2+
to the project to simplify our work later on. Please review them below:
33

44
### Backend changes
5-
- `database.sqlite` file was moved from the backend root directory to the `backend/data` directory.
6-
- Updated `storage` path in the [dbConfig.js][dbConfig] file.
7-
- Added `/health` route in the [index.js][index] file.
8-
- The `.env` file was moved outside the backend directory.
5+
- The `database.sqlite` file has been moved from the backend root directory to the `backend/data` directory.
6+
- The `storage` path has been updated in the [dbConfig.js][dbConfig] file.
7+
- A `/health` route has been added to the [index.js][index] file.
8+
- The `.env` file has been moved outside of the backend directory.
99

1010
### Dockerfile
1111
Now it's time to create a Dockerfile in the project directory.
1212
A Dockerfile is essentially a set of instructions for building an image,
13-
which is a blueprint for our container to run from.
14-
Let's go over this line by line of the backend [Dockerfile][Dockerfile]:
13+
which is a blueprint for our container to run from.
14+
Let's go over the backend [Dockerfile][Dockerfile] line by line:
1515

1616
```Dockerfile
1717
FROM node:20-alpine
@@ -27,15 +27,15 @@ EXPOSE 8000
2727
CMD ["npm", "start"]
2828
```
2929

30-
- The line `FROM node:20-alpine` uses the Node.js 20 image from [Docker Hub](https://hub.docker.com/_/node/) as our base image. This ensures we have Node.js and all its dependencies in the container.
31-
- Using `WORKDIR /app` ensures that the next commands will be executed in that directory.
32-
- We `COPY package*.json ./`, which makes the file available in our Docker image.
30+
- The line `FROM node:20-alpine` uses the Node.js 20 image from [Docker Hub](https://hub.docker.com/_/node/) as the base image. This ensures that the container includes Node.js and all its dependencies.
31+
- Using `WORKDIR /app` ensures that subsequent commands execute in that directory.
32+
- The instruction `COPY package*.json ./` makes the file available in the Docker image.
3333
- Then, we install dependencies using `RUN npm install`.
34-
- We then copy the rest of our source code into a subdirectory `COPY . .`.
35-
- The `EXPOSE 8000` instruction informs Docker that the container listens on port `8000` at runtime. We specified this port in [index.js][index]. The `EXPOSE` instruction doesn't publish the port to your host machine; it simply declares that this port is intended to be published.
36-
- Finally, we state the command to run the application, which is `CMD ["npm", "start"]`.
34+
- The `COPY . .` instruction copies the rest of the source code into a subdirectory.
35+
- The `EXPOSE 8000` instruction informs Docker that the container listens on port `8000` at runtime. We specified this port in [index.js][index]. Note: The `EXPOSE` instruction doesn't publish the port to the host machine; it simply declares that this port is intended to be used.
36+
- Finally, the `CMD ["npm", "start"]` instruction specifies the command to run the application.
3737

38-
We will run backend container later after frontend updates.
38+
We will run the backend container later, after making updates to the frontend.
3939

4040
[dbConfig]: course://Deploy/Containerization/backend_dockerfile/backend/src/data/dbConfig.js
4141
[index]: course://Deploy/Containerization/backend_dockerfile/backend/src/index.js

Deploy/Containerization/docker_compose/task.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
So, we are all set to run both containers with our services.
2-
To make managing them much easier, we will use [Docker Compose](https://docs.docker.com/compose/).
2+
To simplify their management, we will use [Docker Compose](https://docs.docker.com/compose/).
33

4-
**Docker Compose** is a tool that allows us to define the deployment of multiple containers
5-
and has the added benefit of making each container targetable using the service name.
4+
**Docker Compose** is a tool that allows us to define the deployment of multiple containers.
5+
It also enables targeting each container by its service name.
66
All we need to do is create a [docker-compose.yaml][docker-compose.yaml] file in our main directory.
77

88
### docker-compose.yaml
9-
This file declares two services. Each service will have its own container built and run.
9+
This file defines two services, with each service having its own container to be built and run.
1010
Let’s look at the most important sections used to describe the services.
1111

12-
- `build` specifies the path and name of the Dockerfile used to build the image for the container.
13-
- `environment` lists the environment variables that should be set inside the container.
14-
- `env_file` allows environment variables to be loaded from a file without specifying their values here.
12+
- `build`: Specifies the path and name of the Dockerfile used to build the container's image.
13+
- `environment`: Lists the environment variables that should be set inside the container.
14+
- `env_file`: Allows environment variables to be loaded from a file without specifying their values here.
1515
> **Use this approach for secret keys like `JWT_SECRET`.**
16-
> **Also, remember to generate unique `JWT_SECRET` using the script `backend/scripts/generateSecret.js`.**
17-
- `volumes` allows creating persistent storage where data will be saved even if the container restarts.
16+
> **Also, remember to generate a unique `JWT_SECRET` using the `backend/scripts/generateSecret.js` script.**
17+
- `volumes`: Allows creating persistent storage where data is retained even if the container restarts.
1818
For example, the volume `chat-db-data` will store the contents of the `'/app/data'` directory inside the backend container.
19-
- `healthcheck` defines a command whose successful execution will verify the service's health.
20-
- `networks` specifies that our containers will be connected via their own private internal network.
21-
To access another container within this network, you only need to use the service name.
19+
- `healthcheck`: Defines a command that verifies the health of the service by checking its successful execution.
20+
- `networks`: Ensures that our containers are connected via their own private internal network.
21+
To access one container from another within this network, you only need to use the service name.
2222
That’s why we can use a URL like http://backend:8000 inside the frontend container.
23-
- `ports` allows specifying which port on your machine should be mapped to the container’s port (`Host_Port:Container_Port`).
23+
- `ports`: Maps a port on your machine to a port inside the container in the format `Host_Port:Container_Port`.
2424

25-
Note that our application is now only accessible through the frontend,
26-
and the frontend-backend interaction happens via the internal network.
25+
Note that our application is now only accessible via the frontend.
26+
The frontend-backend communication takes place through the internal network.
2727

28-
You can get more information about the Docker Compose in the [official documentation](https://docs.docker.com/compose/).
28+
You can find more information about Docker Compose in the [official documentation](https://docs.docker.com/compose/).
2929

3030
### Launch the application
31-
To launch both services through the terminal, use the following command:
31+
To launch both services from the terminal, use the following command:
3232
```shell
3333
docker compose up -d
3434
```
35-
And the following command to stop them:
35+
To stop the services, run:
3636
```shell
3737
docker compose down
3838
```
3939

40-
To launch them in the IDE, click the ![](images/runAll.svg) button
41-
opposite the `services` in the `docker-compose.yaml` file.
42-
You can see all information about launched services in the [Services](tool_window://Services) toolwindow:
40+
To launch the services in your IDE, click the ![](images/runAll.svg) button
41+
next to `services` in the `docker-compose.yaml` file.
42+
You can view all relevant information about the launched services in the [Services](tool_window://Services) tool window:
4343

4444
<div style="text-align: center; max-width: 600px; margin: 0 auto;">
45-
<img src="images/compose_up.png" alt="Services toolwindow">
45+
<img src="images/compose_up.png" alt="Services tool window">
4646
</div>
4747

4848
Now you can access the application at http://localhost:3000.

Deploy/Containerization/docker_intro/task.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
Docker containers provide code isolation, independence, and portability. Docker is essentially needed
2-
if one intends to deploy their application into production. Docker containers have fully prescribed
3-
dependencies with which they can be created. These dependencies, as well as the application code,
4-
are stored in the container’s **image**.
2+
if you intend to deploy your application to production. Docker containers are created with fully prescribed
3+
dependencies with which they can be created. These dependencies that are stored, along with the application code,
4+
in the container’s **image**.
55

6-
A **Dockerfile** is basically a set of instructions for building a container image, which is a blueprint that your container will run from.
6+
A **Dockerfile** is essentially a set of instructions for building a container image, which serves as a blueprint from which your container runs.
77

88
In our project, we will use separate containers for the backend and frontend code.
99

10-
You can read more about Docker in [Docker docs](https://docs.docker.com/).
10+
You can read more about Docker in the [Docker documentation](https://docs.docker.com/).
1111

1212
### Docker support in JetBrains IDEs
13-
JetBrains IDEs allow you to manage Docker containers using a graphical interface. Only a few simple steps are required to set this up.
13+
JetBrains IDEs allow you to manage Docker containers using a graphical interface with just a few simple steps to set up.
1414

1515
### 1. Install and run Docker
16-
For more information, see the [Docker documentation](https://docs.docker.com/engine/install/) specific to your operating system.
16+
For detailed instructions, refer to the [Docker installation guide](https://docs.docker.com/engine/install/) for your specific operating system.
1717

1818
### 2. Configure the Docker daemon connection settings
1919

2020
1. Open the IDE settings (you can use the shortcut &shortcut:ShowSettings;) and select **Build, Execution, Deployment | Docker**.
2121
2. Click ![](images/add.svg) to add a Docker configuration and specify how to connect to the Docker daemon.
22-
The connection settings depend on your Docker version and operating system. For more information, see [Docker configuration](https://www.jetbrains.com/help/pycharm/settings-docker.html).
23-
The **Connection successful** message should appear at the bottom of the dialog.
22+
The connection settings will depend on your Docker version and operating system. For more information, see the [Docker configuration guide](https://www.jetbrains.com/help/pycharm/settings-docker.html).
23+
If everything is set up correctly, you should see the **Connection successful** message at the bottom of the dialog.
2424

2525
![](images/settings_docker.png)
2626

2727
### 3. Connect to the Docker daemon
28-
The configured Docker connection should appear in the Services tool window (**View | Tool Windows | Services** or &shortcut:ActivateServicesToolWindow;). Select the Docker node ![](images/docker.png) and click ![](images/run.svg), or select **Connect** from the context menu. Once connected, it will look like this:
28+
The configured Docker connection will appear in the Services tool window (**View | Tool Windows | Services** or use the &shortcut:ActivateServicesToolWindow;).
29+
Select the Docker node ![](images/docker.png) and click ![](images/run.svg), or select **Connect** from the context menu. Once connected, it should look like this:
2930
<div style="text-align:center;"><img src="images/services.png" style="width:70%;" alt="Run MyRunConfig"></div>
3031

3132
To edit the Docker connection settings, select the Docker node and click ![](images/edit.svg) on the toolbar, or select **Edit Configuration** from the context menu.

Deploy/Containerization/frontend_dockerfile/task.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
Before we write the Dockerfile for the frontend, we have made a few changes
2-
to the project that will simplify our work later on. Please take a look at them.
2+
to the project to simplify our work later on. Please review them below.
33

44
### Frontend changes
5-
- Images (`academy.svg` and `delete.svg`) were moved to the `public/assets` folder.
6-
This is a default folder for resources and built by a Vite project.
7-
- Paths to the images in [Chat.jsx][Chat] and [index.html][index] files were updated.
8-
- Added a `build` script to [package.json][package].
9-
- Made changes in the [vite.config.js][vite.config] to take `backendUrl` from the environmental variables.
10-
- Created [nginx.conf][nginx]. This is a default configuration file for Nginx where we made few changes like frontend port and backend URLs.
11-
12-
The built-in Vite web server is not intended for use in production.
13-
However, we can use it to build the project and then host it with
5+
- Images (`academy.svg` and `delete.svg`) were moved to the `public/assets` folder.
6+
This is the default resources folder used by a Vite project.
7+
- Paths to the images in the [Chat.jsx][Chat] and [index.html][index] files were updated.
8+
- A `build` script was added to the [package.json][package] file.
9+
- Updates were made to [vite.config.js][vite.config] to retrieve `backendUrl` from the environment variables.
10+
- A new [nginx.conf][nginx] file was created. This is the default configuration file for Nginx, where changes were made, such as specifying the frontend port and backend URLs.
11+
12+
The built-in Vite web server is not designed for production use.
13+
However, it can be used to build the project, which can then be hosted on
1414
a full-featured web server like [Nginx](https://nginx.org/).
1515

1616
You can read more about Nginx configuration in the [official documentation](https://nginx.org/en/docs/beginners_guide.html#conf_structure).
1717

1818
### Dockerfile
19-
Frontend [Dockerfile][Dockerfile] is a bit more complicated than the backend one. It includes 2 stages:
19+
The frontend [Dockerfile][Dockerfile] is slightly more complex than the backend one because it includes two stages:
2020

2121
```dockerfile
2222
# Build stage
@@ -39,14 +39,14 @@ COPY nginx.conf /etc/nginx/conf.d/default.conf
3939
EXPOSE 3000
4040
```
4141

42-
- A build stage is similar to the backend one. But the build artifacts are used in the next stage.
43-
- For the production stage, we use a base image with Nginx already installed: `nginx:alpine`.
42+
- The build stage is similar to the backend process, but its build artifacts are used in the next stage.
43+
- For the production stage, we use `nginx:alpine`, a base image with Nginx already installed.
4444
- Then, we copy the built frontend from the build stage into the Nginx directory: `COPY --from=build /app/dist /usr/share/nginx/html`.
4545
- Next, we copy the configuration file into the image: `COPY nginx.conf /etc/nginx/conf.d/default.conf`.
46-
- Finally, specify that the container listens on port `3000` at runtime.
46+
- Finally, we specify that the container will listen on port `3000` at runtime.
4747

48-
You may have noticed that in [nginx.conf][nginx], URLs like `http://backend:8000/api/` are used without explicitly defining what "backend" is.
49-
In the next step, we’ll explain why this is normal and how to run the backend and frontend together.
48+
You may have noticed that in [nginx.conf][nginx], URLs such as `http://backend:8000/api/` are used without explicitly defining what "backend" refers to.
49+
In the next task, we’ll explain why this works and how to run both the backend and frontend together.
5050

5151
[Chat]: course://Deploy/Containerization/frontend_dockerfile/frontend/src/pages/Chat.jsx
5252
[index]: course://Deploy/Containerization/frontend_dockerfile/frontend/index.html
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
So far, we have been running our project locally, and that was enough for testing.
1+
So far, we have been running our project locally, which has been sufficient for testing.
22

33
In this lesson, we’ll discuss how to adapt our application
44
before deploying it to a server and making it accessible to users.
55

6-
You could manually copy the application to a server, install all dependencies,
7-
and run the application, but this approach is unstable.
8-
For example, migrating the application to a different hosting service could take a long time.
6+
While you could manually copy the application to a server, install all dependencies,
7+
and run it there, this approach is unreliable.
8+
For example, migrating the application to a different hosting service might require significant time.
99

1010
We can avoid these issues by deploying and running the application in a **Docker container**.
1111

12-
From this lesson, you will learn:
13-
- How to write a Dockerfile.
14-
- How to create a Docker Compose file for the project.
15-
- Run your application in a Docker containers in one command.
12+
From this lesson, you will learn how to:
13+
- Write a Dockerfile.
14+
- Create a Docker Compose file for the project.
15+
- Run your application in Docker containers with a single command.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
Let’s summarize briefly. To deploy our application using Docker, you need:
1+
Let’s summarize briefly. To deploy your application using Docker, you need:
22

3-
1. A Dockerfile where we define the environment for our service, install dependencies, and configure the application build process.
4-
2. A Compose file where we describe how our services should be run, what data should be stored in persistent storage, which ports to expose, and more.
5-
3. Store secret keys in a `.env` file, avoid committing it to the repository, and do not set sensitive environment variables in the Dockerfile or Compose file.
3+
1. A Dockerfile where you define the environment for your service, install dependencies, and configure the application build process.
4+
2. A Compose file where you describe how your services should run, what data should be stored in persistent storage, which ports to expose, and other configurations.
5+
3. A `.env` file to store secret keys. Avoid committing this file to the repository, and never set sensitive environment variables directly in the Dockerfile or Compose file.
66

7-
Now you can deploy your application on any server with almost a single command.
7+
Now you can deploy your application to any server with almost a single command.
88

99
Good luck!

0 commit comments

Comments
 (0)