https://github.com/safwen-saafi/multi-service-web-container
Containerize a web app with two main services, a Node api and a go-lang api
https://github.com/safwen-saafi/multi-service-web-container
docker docker-compose golang node react
Last synced: 5 months ago
JSON representation
Containerize a web app with two main services, a Node api and a go-lang api
- Host: GitHub
- URL: https://github.com/safwen-saafi/multi-service-web-container
- Owner: Safwen-Saafi
- License: mit
- Created: 2024-11-07T10:14:36.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-24T00:38:48.000Z (over 1 year ago)
- Last Synced: 2025-03-26T22:51:18.800Z (about 1 year ago)
- Topics: docker, docker-compose, golang, node, react
- Language: JavaScript
- Homepage:
- Size: 296 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sample web application

## Minimal 3 tier web application
- **React frontend:** Uses react query to load data from the two apis and display the result
- **Node JS and Golang APIs:** Both have `/` and `/ping` endpoints. `/` queries the Database for the current time, and `/ping` returns `pong`
- **Postgres Database:** An empty PostgreSQL database with no tables or data. Used to show how to set up connectivity. The API applications execute `SELECT NOW() as now;` to determine the current time to return.

## Running the Application
The `Makefile` contains the commands to start each application.
### Postgres
Postgres is run in a container.
`make run-postgres` will start postgres in a container and publish port 5432 from the container to your localhost.

### api-node
To run the node api you will need to run `npm install` to install the dependencies. They are already present in the package.json file so you don't need to specify them, just run the command and you are good to go.
After installing the dependencies, `make run-api-node` will run the api in development mode with nodemon for restarting the app when you make source code changes.

### api-golang
To run the golang api you will need to run `go mod download` to download and install the dependencies.
After installing the dependencies, `make run-api-golang` will build and run the api.

### client-react
Like `api-node`, you will first need to install the dependencies with `npm install`
After installing the dependencies, `make run-client-react` will use vite to run the react app in development mode.

## What is the goal of this project ?
A very `simple` and `straightforward` web app to `containerize`, with a `Dockerfile` inside each directory.
The whole point of this project is to containerize the app, include each image in a `Docker-compose` file and run the whole web app as `separate containers`.
It's truly a great project to follow along if you're new to `Docker` and it's key concepts.
## How to use the docker-compose ?
All of the necessary commands are included in the Makefile.
First of all `make compose-build` will execute the command `docker compose build` to build all of the images included in the docker-compose
Then `make compose-up` will start all of the containers ( docker compose up)
If you want to stop all of the containers, just run `make compose-down` ( docker compose down)