From 810929b0ad8f36aefe95d4b26835dec065e3ba0f Mon Sep 17 00:00:00 2001 From: nir3shprabu <115976526+nir3shprabu@users.noreply.github.com> Date: Thu, 1 Dec 2022 17:27:05 +0530 Subject: [PATCH 1/9] Add docker files and compose --- api/Dockerfile | 16 ++++++++++++++++ docker-compose.yml | 22 ++++++++++++++++++++++ my-app/Dockerfile | 28 ++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 api/Dockerfile create mode 100644 docker-compose.yml create mode 100644 my-app/Dockerfile diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 00000000..27ee10a1 --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,16 @@ +FROM node:14-alpine + +WORKDIR /back + +# add '/app/node_modules/.bin' to $PATH +# ENV PATH /app/node_modules/.bin:$PATH +# install application dependencies +COPY package*.json ./ +RUN npm install +# RUN npm install react-scripts -g + +# copy app files +COPY . . + +EXPOSE 4000 +CMD ["npm", "start"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..68c137a0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +version: "3.8" +services: + web: + build: ./my-app + depends_on: + - api + ports: + - "3000:3000" + stdin_open: true + networks: + - network-backend + api: + build: ./api + # depends_on: + # - mongo + ports: + - "4000:4000" + networks: + - network-backend + +networks: + network-backend: diff --git a/my-app/Dockerfile b/my-app/Dockerfile new file mode 100644 index 00000000..bf97bfff --- /dev/null +++ b/my-app/Dockerfile @@ -0,0 +1,28 @@ +FROM node:14-alpine + +WORKDIR /app + +# add '/app/node_modules/.bin' to $PATH +# ENV PATH /app/node_modules/.bin:$PATH +# install application dependencies +COPY package*.json ./ +RUN npm install + +# RUN npm install react-scripts -g + +# copy app files +COPY . . + +EXPOSE 3000 +CMD npm start + +# FROM node:14-alpine AS build +# WORKDIR /my-app +# COPY . /my-app/ +# RUN npm i +# RUN npm run build + +# FROM nginx:stable-alpine AS runner +# WORKDIR /usr/share/nginx/html/ +# COPY --from=build /my-app/build /usr/share/nginx/html +# EXPOSE 80 From 1fcf86193aa5c2067f0131ce5d74d722895e68e9 Mon Sep 17 00:00:00 2001 From: nir3shprabu <115976526+nir3shprabu@users.noreply.github.com> Date: Wed, 21 Dec 2022 14:56:37 +0530 Subject: [PATCH 2/9] Fix: update --- Dockerfile | 15 --------------- docker-compose.yml | 6 ++---- docker.stack.yml | 28 ++++++++++++++++++++++++++++ my-app/Dockerfile | 23 +++++------------------ my-app/package.json | 2 +- 5 files changed, 36 insertions(+), 38 deletions(-) delete mode 100644 Dockerfile create mode 100644 docker.stack.yml diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 8fa0e038..00000000 --- a/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM node:10 AS ui-build -WORKDIR /usr/src/app -COPY my-app/ ./my-app/ -RUN cd my-app && npm install && npm run build - -FROM node:10 AS server-build -WORKDIR /root/ -COPY --from=ui-build /usr/src/app/my-app/build ./my-app/build -COPY api/package*.json ./api/ -RUN cd api && npm install -COPY api/server.js ./api/ - -EXPOSE 80 - -CMD ["node", "./api/server.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 68c137a0..2e5fd53c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,16 +5,14 @@ services: depends_on: - api ports: - - "3000:3000" + - "3003:3000" stdin_open: true networks: - network-backend api: build: ./api - # depends_on: - # - mongo ports: - - "4000:4000" + - "4004:4000" networks: - network-backend diff --git a/docker.stack.yml b/docker.stack.yml new file mode 100644 index 00000000..b4d438b5 --- /dev/null +++ b/docker.stack.yml @@ -0,0 +1,28 @@ +version : "3.8" +services: + my-app: + image: + deploy: + mode: replicated + replicas: 2 + restart_policy: + condition: on-failure + # To place in particular node + # placement: + # constraints: [node.hostname == ] + ports: + - "3000:3000" + api: + image: + deploy: + mode: replicated + replicas: 2 + restart_policy: + condition: on-failure + # To place in particular node + # placement: + # constraints: [node.hostname == ] + ports: + - "4000:4000" + volumes: + - "/var/run/docker.sock:/var/run/docker.sock" diff --git a/my-app/Dockerfile b/my-app/Dockerfile index bf97bfff..d0aaf69f 100644 --- a/my-app/Dockerfile +++ b/my-app/Dockerfile @@ -1,28 +1,15 @@ FROM node:14-alpine -WORKDIR /app +WORKDIR /sample -# add '/app/node_modules/.bin' to $PATH -# ENV PATH /app/node_modules/.bin:$PATH -# install application dependencies COPY package*.json ./ -RUN npm install -# RUN npm install react-scripts -g +RUN npm install -# copy app files COPY . . -EXPOSE 3000 -CMD npm start +RUN sed -i 's/localhost/api/g' package.json -# FROM node:14-alpine AS build -# WORKDIR /my-app -# COPY . /my-app/ -# RUN npm i -# RUN npm run build +EXPOSE 3000 -# FROM nginx:stable-alpine AS runner -# WORKDIR /usr/share/nginx/html/ -# COPY --from=build /my-app/build /usr/share/nginx/html -# EXPOSE 80 +CMD ["npm", "start"] diff --git a/my-app/package.json b/my-app/package.json index 29c0a4e2..7d727315 100644 --- a/my-app/package.json +++ b/my-app/package.json @@ -13,7 +13,7 @@ "react-scripts": "3.4.1" }, "scripts": { - "start": "react-scripts start --port 3001", + "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" From bf9b06fa3ed6d7afc821b65be5303df3c893fb5a Mon Sep 17 00:00:00 2001 From: Niresh Prabu <115976526+nir3shprabu@users.noreply.github.com> Date: Wed, 21 Dec 2022 15:07:53 +0530 Subject: [PATCH 3/9] Create README.md --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..cd315184 --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +# react-nodejs-example +## Docker +#### Create Dockerfile and write commands using the reference given above +>step1: Creating Docker image in frontend using : +>`docker build -t . + +>step2: Creating Docker image in backend using : +>`cd backend/` +>`docker build -t . ` + +>step3: Creating container using Docker image by this command : +`docker run -itd --name -p ` + +>step4: Checking the containers created using : +>To see running containers : +>` docker ps ` +>To see running and non-running containers : +>` docker ps -a ` + +>step5: In browser exposing the container by : +>`localhost:portno` + +## Dockercompose +#### Nameformat for docker compose file creation: `docker-compose.yml` +**To run:** `docker compose up -d` +**To stop:** `docker compose down -d` +**For expose:** In browser `ipaddr:portno` + +## Dockerswarm +#### Nameformat for docker stack file creation: `docker.stack.yml` +>step1: Initializing dockerswarm in manager node by : +>`docker swarm init --advertise-addr ` + +>step2: Assigning workernode for managernode using token : +>`docker swarm join --token (token will be provided after executing step1)` + +>step3: Creating the dockerstackfile by : +>`vi docker.stack.yml` + +>step4: Deploying the docker stack using : +>`docker stack deploy -c docker.stack.yml ` + +>step5: Exposing the container in browser by : +>`ipaddr:portno` From 94d4f7f9dfe9bc01d1a780d22bf3a4c5ee8fc96b Mon Sep 17 00:00:00 2001 From: nir3shprabu <115976526+nir3shprabu@users.noreply.github.com> Date: Thu, 2 Feb 2023 17:47:29 +0530 Subject: [PATCH 4/9] fix: Fix README.md --- README.md | 121 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index cd315184..dfb44ff9 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,77 @@ -# react-nodejs-example -## Docker -#### Create Dockerfile and write commands using the reference given above ->step1: Creating Docker image in frontend using : ->`docker build -t . - ->step2: Creating Docker image in backend using : ->`cd backend/` ->`docker build -t . ` - ->step3: Creating container using Docker image by this command : -`docker run -itd --name -p ` - ->step4: Checking the containers created using : ->To see running containers : ->` docker ps ` ->To see running and non-running containers : ->` docker ps -a ` - ->step5: In browser exposing the container by : ->`localhost:portno` - -## Dockercompose -#### Nameformat for docker compose file creation: `docker-compose.yml` -**To run:** `docker compose up -d` -**To stop:** `docker compose down -d` -**For expose:** In browser `ipaddr:portno` - -## Dockerswarm -#### Nameformat for docker stack file creation: `docker.stack.yml` ->step1: Initializing dockerswarm in manager node by : ->`docker swarm init --advertise-addr ` - ->step2: Assigning workernode for managernode using token : ->`docker swarm join --token (token will be provided after executing step1)` - ->step3: Creating the dockerstackfile by : ->`vi docker.stack.yml` - ->step4: Deploying the docker stack using : ->`docker stack deploy -c docker.stack.yml ` - ->step5: Exposing the container in browser by : ->`ipaddr:portno` +# Table of Contents +- [Docker Compose ](#docker-compose-v2) +- [Where to get Docker Compose](#where-to-get-docker-compose) + + [Windows and macOS](#windows-and-macos) + + [Linux](#linux) +- [Quick Start](#quick-start) +- [Contributing](#contributing) +# Docker Compose + +[![GitHub release](https://img.shields.io/github/release/docker/compose.svg?style=flat-square)](https://github.com/docker/compose/releases/latest) +[![PkgGoDev](https://img.shields.io/badge/go.dev-docs-007d9c?style=flat-square&logo=go&logoColor=white)](https://pkg.go.dev/github.com/docker/compose/v2) +[![Build Status](https://img.shields.io/github/workflow/status/docker/compose/ci?label=ci&logo=github&style=flat-square)](https://github.com/docker/compose/actions?query=workflow%3Aci) +[![Go Report Card](https://goreportcard.com/badge/github.com/docker/compose/v2?style=flat-square)](https://goreportcard.com/report/github.com/docker/compose/v2) +[![Codecov](https://codecov.io/gh/docker/compose/branch/master/graph/badge.svg?token=HP3K4Y4ctu)](https://codecov.io/gh/docker/compose) +[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/docker/compose/badge)](https://api.securityscorecards.dev/projects/github.com/docker/compose) +![Docker Compose](logo.png?raw=true "Docker Compose Logo") + +Docker Compose is a tool for running multi-container applications on Docker +defined using the [Compose file format](https://compose-spec.io). +A Compose file is used to define how one or more containers that make up +your application are configured. +Once you have a Compose file, you can create and start your application with a +single command: `docker compose up`. + + +# Where to get Docker Compose + +### Windows and macOS + +Docker Compose is included in +[Docker Desktop](https://www.docker.com/products/docker-desktop) +for Windows and macOS. + +### Linux + +You can download Docker Compose binaries from the +[release page](https://github.com/docker/compose/releases) on this repository. + +Rename the relevant binary for your OS to `docker-compose` and copy it to `$HOME/.docker/cli-plugins` + +Or copy it into one of these folders to install it system-wide: + +* `/usr/local/lib/docker/cli-plugins` OR `/usr/local/libexec/docker/cli-plugins` +* `/usr/lib/docker/cli-plugins` OR `/usr/libexec/docker/cli-plugins` + +(might require making the downloaded file executable with `chmod +x`) + + +Quick Start +----------- + +Using Docker Compose is a three-step process: +1. Define your app's environment with a `Dockerfile` so it can be + reproduced anywhere. +2. Define the services that make up your app in `docker-compose.yml` so + they can be run together in an isolated environment. +3. Lastly, run `docker compose up` and Compose will start and run your entire + app. + +A Compose file looks like this: + +```yaml +services: + web: + build: . + ports: + - "5000:5000" + volumes: + - .:/code + redis: + image: redis +``` + +Contributing +------------ + +Dont hesitate to create a pull request \ No newline at end of file From b83f071516f6077d1857a872c74f05caea842206 Mon Sep 17 00:00:00 2001 From: nir3shprabu <115976526+nir3shprabu@users.noreply.github.com> Date: Thu, 2 Feb 2023 18:03:08 +0530 Subject: [PATCH 5/9] fix: Fix README.md --- .gitignore | 3 +++ README.md | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 02c7449e..020b4db5 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,9 @@ /my-app/node_modules /api/node_modules +*COMPOSE.png* + + # profiling files chrome-profiler-events*.json speed-measure-plugin*.json diff --git a/README.md b/README.md index dfb44ff9..1b4b6c0f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,8 @@ [![Go Report Card](https://goreportcard.com/badge/github.com/docker/compose/v2?style=flat-square)](https://goreportcard.com/report/github.com/docker/compose/v2) [![Codecov](https://codecov.io/gh/docker/compose/branch/master/graph/badge.svg?token=HP3K4Y4ctu)](https://codecov.io/gh/docker/compose) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/docker/compose/badge)](https://api.securityscorecards.dev/projects/github.com/docker/compose) -![Docker Compose](logo.png?raw=true "Docker Compose Logo") +![Docker Compose](COMPOSE.png?raw=true "Docker Compose Logo") + Docker Compose is a tool for running multi-container applications on Docker defined using the [Compose file format](https://compose-spec.io). From 3aa4bf0cd2ddd138d84795c60ac20fae6bd72f2b Mon Sep 17 00:00:00 2001 From: nir3shprabu <115976526+nir3shprabu@users.noreply.github.com> Date: Thu, 2 Feb 2023 18:07:09 +0530 Subject: [PATCH 6/9] fix: Fix README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1b4b6c0f..5738eb8e 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ [![Go Report Card](https://goreportcard.com/badge/github.com/docker/compose/v2?style=flat-square)](https://goreportcard.com/report/github.com/docker/compose/v2) [![Codecov](https://codecov.io/gh/docker/compose/branch/master/graph/badge.svg?token=HP3K4Y4ctu)](https://codecov.io/gh/docker/compose) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/docker/compose/badge)](https://api.securityscorecards.dev/projects/github.com/docker/compose) -![Docker Compose](COMPOSE.png?raw=true "Docker Compose Logo") +![Docker Compose](https://jeddict.github.io/tutorial/Docker/COMPOSE.png?raw=true "Docker Compose Logo") Docker Compose is a tool for running multi-container applications on Docker From 32033777eac0a9459f33c6d62901ecd9bfdc7596 Mon Sep 17 00:00:00 2001 From: Niresh Prabu <115976526+nir3shprabu@users.noreply.github.com> Date: Thu, 2 Feb 2023 18:09:56 +0530 Subject: [PATCH 7/9] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5738eb8e..f65d91e5 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ [![Go Report Card](https://goreportcard.com/badge/github.com/docker/compose/v2?style=flat-square)](https://goreportcard.com/report/github.com/docker/compose/v2) [![Codecov](https://codecov.io/gh/docker/compose/branch/master/graph/badge.svg?token=HP3K4Y4ctu)](https://codecov.io/gh/docker/compose) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/docker/compose/badge)](https://api.securityscorecards.dev/projects/github.com/docker/compose) -![Docker Compose](https://jeddict.github.io/tutorial/Docker/COMPOSE.png?raw=true "Docker Compose Logo") +![Docker Compose](https://jeddict.github.io/tutorial/Docker/COMPOSE.png "Docker Compose Logo") Docker Compose is a tool for running multi-container applications on Docker @@ -75,4 +75,4 @@ services: Contributing ------------ -Dont hesitate to create a pull request \ No newline at end of file +Dont hesitate to create a pull request From 4b63319d129bc1f8c19739618c7f490a0385f737 Mon Sep 17 00:00:00 2001 From: nir3shprabu <115976526+nir3shprabu@users.noreply.github.com> Date: Wed, 15 Mar 2023 13:15:54 +0530 Subject: [PATCH 8/9] docs: Update README.md --- README.md | 84 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index f65d91e5..f15510c1 100644 --- a/README.md +++ b/README.md @@ -1,50 +1,64 @@ -# Table of Contents -- [Docker Compose ](#docker-compose-v2) -- [Where to get Docker Compose](#where-to-get-docker-compose) - + [Windows and macOS](#windows-and-macos) - + [Linux](#linux) -- [Quick Start](#quick-start) -- [Contributing](#contributing) -# Docker Compose +# react-nodejs-example -[![GitHub release](https://img.shields.io/github/release/docker/compose.svg?style=flat-square)](https://github.com/docker/compose/releases/latest) -[![PkgGoDev](https://img.shields.io/badge/go.dev-docs-007d9c?style=flat-square&logo=go&logoColor=white)](https://pkg.go.dev/github.com/docker/compose/v2) -[![Build Status](https://img.shields.io/github/workflow/status/docker/compose/ci?label=ci&logo=github&style=flat-square)](https://github.com/docker/compose/actions?query=workflow%3Aci) -[![Go Report Card](https://goreportcard.com/badge/github.com/docker/compose/v2?style=flat-square)](https://goreportcard.com/report/github.com/docker/compose/v2) -[![Codecov](https://codecov.io/gh/docker/compose/branch/master/graph/badge.svg?token=HP3K4Y4ctu)](https://codecov.io/gh/docker/compose) -[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/docker/compose/badge)](https://api.securityscorecards.dev/projects/github.com/docker/compose) -![Docker Compose](https://jeddict.github.io/tutorial/Docker/COMPOSE.png "Docker Compose Logo") +## Available Scripts +In the project directory, you can run: -Docker Compose is a tool for running multi-container applications on Docker -defined using the [Compose file format](https://compose-spec.io). -A Compose file is used to define how one or more containers that make up -your application are configured. -Once you have a Compose file, you can create and start your application with a -single command: `docker compose up`. +### `npm start` + +Runs the app in the development mode.\ +Open [http://localhost:8080](http://localhost:8080) to view it in your browser. + +The page will reload when you make changes.\ +You may also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.\ +See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.\ +It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.\ +Your app is ready to be deployed! +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. -# Where to get Docker Compose +### `npm run eject` -### Windows and macOS +**Note: this is a one-way operation. Once you `eject`, you can't go back!** -Docker Compose is included in -[Docker Desktop](https://www.docker.com/products/docker-desktop) -for Windows and macOS. +If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. -### Linux +Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. -You can download Docker Compose binaries from the -[release page](https://github.com/docker/compose/releases) on this repository. +You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. -Rename the relevant binary for your OS to `docker-compose` and copy it to `$HOME/.docker/cli-plugins` +# Docker -Or copy it into one of these folders to install it system-wide: +![Docker](https://jeddict.github.io/tutorial/Docker/DOCKER.png) -* `/usr/local/lib/docker/cli-plugins` OR `/usr/local/libexec/docker/cli-plugins` -* `/usr/lib/docker/cli-plugins` OR `/usr/libexec/docker/cli-plugins` +Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. + +# Dockerfile + +A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image + +# Docker Compose + +![Docker Compose](https://jeddict.github.io/tutorial/Docker/COMPOSE.png "Docker Compose Logo") + + +Docker Compose is a tool for running multi-container applications on Docker +defined using the [Compose file format](https://compose-spec.io). +A Compose file is used to define how one or more containers that make up +your application are configured. +Once you have a Compose file, you can create and start your application with a +single command: `docker compose up`. -(might require making the downloaded file executable with `chmod +x`) Quick Start @@ -69,7 +83,7 @@ services: volumes: - .:/code redis: - image: redis + image: nginx ``` Contributing From 9b0eccce872b0917831d2dc19668f46fec2a512a Mon Sep 17 00:00:00 2001 From: nir3shprabu <115976526+nir3shprabu@users.noreply.github.com> Date: Wed, 15 Mar 2023 13:24:56 +0530 Subject: [PATCH 9/9] docs: Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f15510c1..9b6b8e80 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # react-nodejs-example +This is an application which contains a connected nodejs backend to a react frontend + ## Available Scripts In the project directory, you can run: