|
1 | | -# Docker Container Setup - Documentation |
| 1 | +# Docker Container Setup - Beginner-Friendly Guide |
2 | 2 |
|
3 | | -This is the documentation on how to containerize and run the recode hive website while using Docker. |
| 3 | +This guide explains how to set up and run the Recode Hive website using Docker in the simplest way possible. |
4 | 4 |
|
5 | | -## Prerequesites |
| 5 | +## Prerequisites |
6 | 6 |
|
7 | | -- [Docker](https://docs.docker.com/engine/install/) installed |
8 | | -- Docker compose installed (Optional) |
| 7 | +- Install [Docker](https://docs.docker.com/engine/install/). |
| 8 | +- Install Docker Compose (usually included with Docker Desktop). |
9 | 9 |
|
10 | 10 | ## Steps |
11 | 11 |
|
12 | | -### 1. Create a `Dockerfile` in the root directory |
| 12 | +### 1. Start the Application with Docker Compose |
13 | 13 |
|
14 | | -This is a text document that contains all the commands needs to build a Docker image. Basically a blue print of a docker image. |
| 14 | +The easiest way to run the application is by using Docker Compose. Simply run the following command in the project root directory: |
15 | 15 |
|
16 | | -Key instructions include <br> |
| 16 | +```bash |
| 17 | +docker-compose up --build |
| 18 | +``` |
| 19 | + |
| 20 | +This command will: |
| 21 | +- Build the Docker image. |
| 22 | +- Start the container. |
| 23 | +- Map port `3000` from the container to your local machine. |
| 24 | + |
| 25 | +Once the setup is complete, visit [http://localhost:3000](http://localhost:3000) to view the site. |
17 | 26 |
|
18 | | -- `FROM <base_image>:<tag>` : The first instruction and specifies the base image to build upon. |
19 | | -- `WORKDIR <path>` : Sets the working directory inside the container for subsequent instructions. |
20 | | -- `COPY <source> <destination>` : This instruction copies files or directories from your local machine (the build context) into the Docker image. |
21 | | -- `RUN <command>` : Executes commands during the image build process. This is used for installing dependencies, updating packages etc. |
22 | | -- `EXPOSE <port>` : Informs docker that the container listens on the specified ports at runtime. |
| 27 | +### 2. Stop the Application |
23 | 28 |
|
24 | | -### 2. Build the Docker Image |
| 29 | +To stop the application, press `Ctrl+C` in the terminal where the application is running. Then, remove the containers with: |
25 | 30 |
|
26 | 31 | ```bash |
27 | | -docker build -t recodehive-app . |
| 32 | +docker-compose down |
28 | 33 | ``` |
29 | 34 |
|
30 | | -This command builds the Docker image using the instructions in the Dockerfile and tags it as recodehive-app. |
| 35 | +### 3. Debugging Tips |
31 | 36 |
|
32 | | -### 3. Run the Container |
| 37 | +- **View Logs:** If you encounter issues, check the container logs: |
| 38 | + ```bash |
| 39 | + docker-compose logs |
| 40 | + ``` |
| 41 | +- **Rebuild the Image:** If you make changes to the code, rebuild the image: |
| 42 | + ```bash |
| 43 | + docker-compose up --build |
| 44 | + ``` |
| 45 | +- **Access the Container Shell:** To debug inside the container: |
| 46 | + ```bash |
| 47 | + docker exec -it <container_name> sh |
| 48 | + ``` |
33 | 49 |
|
34 | | -```bash |
35 | | -docker run -p 3000:3000 recodehive-app |
36 | | -``` |
| 50 | +### Notes |
| 51 | + |
| 52 | +- The `docker-compose.yml` file is pre-configured for development. |
| 53 | +- The application is set to bind to `0.0.0.0` for external access. |
| 54 | +- File changes on your local machine will automatically reflect in the container (hot-reloading enabled). |
37 | 55 |
|
38 | | -This runs the container and maps port 3000 from the container to your local machine. <br> |
39 | | -Now Visit http://localhost:3000 to view the site. |
| 56 | +For more details, refer to the official Docker documentation. |
40 | 57 |
|
0 commit comments