Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions templates/mern/javascript/client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use an official Node.js runtime as a parent image
FROM node:20-alpine

# Set the working directory in the container
WORKDIR /usr/src/app

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

# Install application dependencies
RUN npm install

# Copy the rest of the application source code
COPY . .

# The client app runs on port 3000, so we expose that
EXPOSE 3000

# Define the command to run the application
CMD [ "npm", "run", "dev" ]
2 changes: 1 addition & 1 deletion templates/mern/javascript/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite --host",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview"
Expand Down
47 changes: 47 additions & 0 deletions templates/mern/javascript/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Specifies the Docker Compose file format version
version: '3.8'

# Defines the services (containers) that make up your app
services:
# The backend Express server
server:
# Tells Docker to build an image from the Dockerfile in the ./server directory
build: ./server
# Names the container so it's easy to identify
container_name: celtrix-mern-server
# Sets environment variables for the server, like the database connection string
environment:
- MONGO_URI=mongodb://mongodb:27017/celtrix-db
# Maps port 4000 on your computer to port 4000 in the container
ports:
- "4000:4000"
# Makes this service depend on the 'mongodb' service. It will wait for mongodb to start.
depends_on:
- mongodb

# The frontend React client
client:
build: ./client
container_name: celtrix-mern-client
# Maps port 3000 on your computer to port 3000 in the container
ports:
- "3000:5173"
# Makes the client depend on the server, ensuring the backend starts first
depends_on:
- server

# The MongoDB database
mongodb:
# Pulls the official MongoDB image from Docker Hub
image: mongo:latest
container_name: celtrix-mern-mongodb
# Maps the default MongoDB port
ports:
- "27017:27017"
# Creates a volume to persist database data even if the container is removed
volumes:
- mongo-data:/data/db

# Defines a named volume for persisting database data
volumes:
mongo-data:
20 changes: 20 additions & 0 deletions templates/mern/javascript/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use an official Node.js runtime as a parent image
FROM node:18-alpine

# Set the working directory in the container
WORKDIR /usr/src/app

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

# Install application dependencies
RUN npm install

# Copy the rest of the application source code
COPY . .

# Expose the port the app runs on
EXPOSE 4000

# Define the command to run the application
CMD [ "npm", "start" ]