diff --git a/.dockerignore b/.dockerignore index 28ef8f24..65b12e38 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,10 @@ node_modules +npm-debug.log +Dockerfile +docker-compose.yml +.dockerignore .git +.gitignore +logs .DS_Store build diff --git a/Dockerfile b/Dockerfile index fdb99554..44660868 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,25 @@ -FROM node:20-alpine +FROM node:20-alpine AS builder WORKDIR /app COPY package*.json ./ +# Install sharp dependencies +RUN apk add --no-cache \ + g++ \ + make \ + python3 \ + libc6-compat + +# Update npm to the latest version +RUN npm install -g npm@latest + RUN npm install --legacy-peer-deps COPY . . -# No need to run 'npm run build' for development-mode Docker +# Expose the application port EXPOSE 3000 -CMD [ "npm", "run", "dev" ] +# Start the application +CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"] diff --git a/docker-compose.yml b/docker-compose.yml index 69493307..313de46b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: - .:/app - /app/node_modules # Prevents node_modules being overwritten by the mount working_dir: /app - command: npm run dev -- --host 0.0.0.0 # THIS is the crucial change for hot-reload! + command: npm run dev -- --host 0.0.0.0 # Ensure the server binds to 0.0.0.0 environment: - NODE_ENV=development - CHOKIDAR_USEPOLLING=true diff --git a/docker-setup.md b/docker-setup.md index c83deba9..588c16c6 100644 --- a/docker-setup.md +++ b/docker-setup.md @@ -1,40 +1,57 @@ -# Docker Container Setup - Documentation +# Docker Container Setup - Beginner-Friendly Guide -This is the documentation on how to containerize and run the recode hive website while using Docker. +This guide explains how to set up and run the Recode Hive website using Docker in the simplest way possible. -## Prerequesites +## Prerequisites -- [Docker](https://docs.docker.com/engine/install/) installed -- Docker compose installed (Optional) +- Install [Docker](https://docs.docker.com/engine/install/). +- Install Docker Compose (usually included with Docker Desktop). ## Steps -### 1. Create a `Dockerfile` in the root directory +### 1. Start the Application with Docker Compose -This is a text document that contains all the commands needs to build a Docker image. Basically a blue print of a docker image. +The easiest way to run the application is by using Docker Compose. Simply run the following command in the project root directory: -Key instructions include
+```bash +docker-compose up --build +``` + +This command will: +- Build the Docker image. +- Start the container. +- Map port `3000` from the container to your local machine. + +Once the setup is complete, visit [http://localhost:3000](http://localhost:3000) to view the site. -- `FROM :` : The first instruction and specifies the base image to build upon. -- `WORKDIR ` : Sets the working directory inside the container for subsequent instructions. -- `COPY ` : This instruction copies files or directories from your local machine (the build context) into the Docker image. -- `RUN ` : Executes commands during the image build process. This is used for installing dependencies, updating packages etc. -- `EXPOSE ` : Informs docker that the container listens on the specified ports at runtime. +### 2. Stop the Application -### 2. Build the Docker Image +To stop the application, press `Ctrl+C` in the terminal where the application is running. Then, remove the containers with: ```bash -docker build -t recodehive-app . +docker-compose down ``` -This command builds the Docker image using the instructions in the Dockerfile and tags it as recodehive-app. +### 3. Debugging Tips -### 3. Run the Container +- **View Logs:** If you encounter issues, check the container logs: + ```bash + docker-compose logs + ``` +- **Rebuild the Image:** If you make changes to the code, rebuild the image: + ```bash + docker-compose up --build + ``` +- **Access the Container Shell:** To debug inside the container: + ```bash + docker exec -it sh + ``` -```bash -docker run -p 3000:3000 recodehive-app -``` +### Notes + +- The `docker-compose.yml` file is pre-configured for development. +- The application is set to bind to `0.0.0.0` for external access. +- File changes on your local machine will automatically reflect in the container (hot-reloading enabled). -This runs the container and maps port 3000 from the container to your local machine.
-Now Visit http://localhost:3000 to view the site. +For more details, refer to the official Docker documentation.