Skip to content

An application serving up business contacts, via Node, Express, and React

Notifications You must be signed in to change notification settings

MultiverseLearningProducts/business-contacts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

business-contacts

An application serving up business contacts, via Node, Express, and React

👉 Client Dockerfile setup

  1. Locate the client folder directory.
  2. Create a new file named Dockerfile in the client directory.
  3. Copy the following instructions into the Dockerfile:
FROM node

WORKDIR /app

COPY . .

RUN npm install && npm run build

EXPOSE 1234

CMD ["node", "server.js"]
  1. Make sure that all the project files are inside the directory, otherwise the COPY . /app command will not work correctly.

  2. In the terminal, navigate to the project directory and run the following command:

docker build -t project-name 

This command will build the Docker image and tag it as "project-name".

  1. To run the container, use the following command:
docker run -p 1234:1234 project-name

This command will run the container and map the host port 1234 to the container's port 1234.

  1. The service can be accessed via http://localhost:1234

👉 Server Dockerfile setup

  1. Create a new folder named server in your project directory.
  2. Using a text editor, create a new file named Dockerfile in the server folder.
  3. Copy the following instructions into the Dockerfile:
FROM node
ENV NODE_ENV=development
WORKDIR /app
COPY package.json .
RUN npm install 
COPY . .
EXPOSE 3000
CMD [ "node", "server.js" ]
  1. In the terminal, navigate to the server directory and run the following command:
docker build -t server-image 

This command will build the Docker image and tag it as "server-image".

  1. To run the container, use the following command:
docker run -p 3000:3000 server-image

Docker commands:

docker build -t name-of-image
docker run -p matchPort:matchPort name-of-image

Options for Running

Option 1 - Run in development (or just without docker)

The point of this example is not to run the apps independently, but if you prefer, or if you're developing/updating them, you can run them independently:

  • Open 2 terminals
  • In one terminal, run cd server and npm run start-dev (runs in watch mode on port 3000)
  • In the other terminal, run cd client and npm start (runs in watch mode on port 1234)
  • Visit the app at localhost:1234

Option 2 - Running with docker-compose

🚨 NOTE 🚨 If you have run the app locally first via above commands, you'll need to delete the node_modules directory in at least the client project. (this is because of a bug in one of the dependencies of Parcel, and a different version of Parcel is used in a Linux environment than in a Mac environment)

Once you have created the docker-compose.yml:

  • If not done already, install Docker Desktop
  • run docker-compose up
  • Visit the app at localhost:1234
  • To stop the app: docker-compose down --rmi all (this also removes all images)

About

An application serving up business contacts, via Node, Express, and React

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published