Skip to content

Commit

Permalink
Dockerize the Application (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayura-andrew authored Jan 4, 2024
1 parent 7f70862 commit adc3a67
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Use an official Node.js runtime as the base image
FROM node:18

# Set the working directory in the Docker container to /app
WORKDIR /app/src

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install any needed packages specified in package.json
RUN npm install

# Bundle the app source inside the Docker image
# (assuming your app is in the "src" directory of your project)
COPY . .

# Make port 8080 available to the world outside this container
EXPOSE 8080

# Run the app when the container launches
CMD [ "npm", "start" ]

31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,37 @@ Follow these steps to get started with the ScholarX backend:

7. Open your web browser and navigate to `http://localhost:${server_port}` to access the running server.

## Docker Setup

If you prefer to use Docker for development, follow these steps:

1. Ensure Docker and Docker Compose are installed on your machine. You can download them from here https://www.docker.com/products/docker-desktop/.

2. Build the Docker images:

```docker-compose build```

3. Start the Docker containers:

```docker-compose up```

4. The application and its services are now running in Docker containers. You can access the application at ```http://localhost:${SERVER_PORT}```, where ```SERVER_PORT``` is the port number specified in your ```.env``` file.

5. To stop the Docker containers, use the following commnd:

```docker-compose down```

Please note that the Docker Compose setup assumes that you have a ```.env``` file in your project root. You can create one by copying the ```.env.example``` file:

```cp .env.example .env```

Then, replace the environment variables in the newly created ```.env``` file with your configuration.


Remember to replace ```${SERVER_PORT}``` with the actual port number if it's a fixed value. If it's specified in the ```.env``` file, you can leave it as is.

---

#### Code Quality

We strive to maintain a high code quality. You can check for linting issues by running:
Expand Down
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3'
services:
app:
build: .
ports:
- "${SERVER_PORT}:3000"
depends_on:
- db
environment:
- DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
- JWT_SECRET=${JWT_SECRET}
db:
image: postgres:13
environment:
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_NAME}

0 comments on commit adc3a67

Please sign in to comment.