Skip to content

Add Docker compose and Docker stack #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
/my-app/node_modules
/api/node_modules

*COMPOSE.png*


# profiling files
chrome-profiler-events*.json
speed-measure-plugin*.json
Expand Down
15 changes: 0 additions & 15 deletions Dockerfile

This file was deleted.

94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# 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:

### `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.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

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.

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 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.

# Docker

![Docker](https://jeddict.github.io/tutorial/Docker/DOCKER.png)

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`.



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: nginx
```

Contributing
------------

Dont hesitate to create a pull request
16 changes: 16 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "3.8"
services:
web:
build: ./my-app
depends_on:
- api
ports:
- "3003:3000"
stdin_open: true
networks:
- network-backend
api:
build: ./api
ports:
- "4004:4000"
networks:
- network-backend

networks:
network-backend:
28 changes: 28 additions & 0 deletions docker.stack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version : "3.8"
services:
my-app:
image: <imagename>
deploy:
mode: replicated
replicas: 2
restart_policy:
condition: on-failure
# To place in particular node
# placement:
# constraints: [node.hostname == <hostname>]
ports:
- "3000:3000"
api:
image: <imagename>
deploy:
mode: replicated
replicas: 2
restart_policy:
condition: on-failure
# To place in particular node
# placement:
# constraints: [node.hostname == <hostname>]
ports:
- "4000:4000"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
15 changes: 15 additions & 0 deletions my-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:14-alpine

WORKDIR /sample

COPY package*.json ./

RUN npm install

COPY . .

RUN sed -i 's/localhost/api/g' package.json

EXPOSE 3000

CMD ["npm", "start"]
2 changes: 1 addition & 1 deletion my-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down