|
1 | 1 | 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/). |
3 | 3 |
|
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. |
6 | 6 | All we need to do is create a [docker-compose.yaml][docker-compose.yaml] file in our main directory. |
7 | 7 |
|
8 | 8 | ### 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. |
10 | 10 | Let’s look at the most important sections used to describe the services. |
11 | 11 |
|
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. |
15 | 15 | > **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. |
18 | 18 | 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. |
22 | 22 | 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`. |
24 | 24 |
|
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. |
27 | 27 |
|
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/). |
29 | 29 |
|
30 | 30 | ### 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: |
32 | 32 | ```shell |
33 | 33 | docker compose up -d |
34 | 34 | ``` |
35 | | -And the following command to stop them: |
| 35 | +To stop the services, run: |
36 | 36 | ```shell |
37 | 37 | docker compose down |
38 | 38 | ``` |
39 | 39 |
|
40 | | -To launch them in the IDE, click the  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  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: |
43 | 43 |
|
44 | 44 | <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"> |
46 | 46 | </div> |
47 | 47 |
|
48 | 48 | Now you can access the application at http://localhost:3000. |
|
0 commit comments