diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..28ef8f24 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +node_modules +.git +.DS_Store +build diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..915af286 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM node:18-alpine AS builder + +# Set working directory inside the container +WORKDIR /app + +COPY package*.json ./ + +# Install dependencies with legacy peer deps fix +RUN npm install --legacy-peer-deps + +COPY . . +RUN npm run build + +# Production Image +FROM node:18-alpine +WORKDIR /app +COPY --from=builder /app /app +EXPOSE 3000 + +CMD ["npm", "run","serve"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..3b09ec5c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3.9" + +services: + recodehive: + build: + context: . + ports: + - "3000:3000" + volumes: + - .:/app + - /app/node_modules + working_dir: /app + command: npm run start + environment: + - NODE_ENV=development diff --git a/docker-setup.md b/docker-setup.md new file mode 100644 index 00000000..c404e1ad --- /dev/null +++ b/docker-setup.md @@ -0,0 +1,30 @@ +# Docker Container Setup - Documentation + +This is the documentation on how to containerize and run the Recodehive website while using Docker. + +## Prerequesites +- [Docker](https://docs.docker.com/engine/install/) installed +- Docker compose installed (Optional) + +## Steps +### 1. Create a `Dockerfile` in the root directory +This is a text document that contains all the commands needs to build a Docker image. Basically a blue print of a docker image. + +Key instructions include
+- `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. Build the Docker Image +```bash +docker build -t recodehive-app . +``` +This command builds the Docker image using the instructions in the Dockerfile and tags it as recodehive-app. +### 3. Run the Container +```bash +docker run -p 3000:3000 recodehive-app +``` +This runs the container and maps port 3000 from the container to your local machine.
+Now Visit http://localhost:3000 to view the site. \ No newline at end of file