Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/afa-farkhod/logs-management
Docker multiple containers logs management into one *.json file
https://github.com/afa-farkhod/logs-management
docker docker-container docker-image dockerfile json
Last synced: about 1 month ago
JSON representation
Docker multiple containers logs management into one *.json file
- Host: GitHub
- URL: https://github.com/afa-farkhod/logs-management
- Owner: afa-farkhod
- License: apache-2.0
- Created: 2023-09-28T08:47:09.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-29T00:46:11.000Z (over 1 year ago)
- Last Synced: 2024-04-24T11:08:03.027Z (9 months ago)
- Topics: docker, docker-container, docker-image, dockerfile, json
- Language: Shell
- Homepage:
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Logs-Management
Docker multiple containers logs management into one *.json file## [Implementation](https://github.com/af4092/Logs-Management/tree/main/docker_logs_test)
1. We first build two `node.js` source files one for `sender.js` which sends message to server and another one is `server.js` server which runs on `port:3001`.
2. Then we make `Dockerfile` for both `sender.js` and `server.js` applications.- `Dockerfile.server` is as following:
```
# Use a base image
FROM node:latest
# Set the working directory
WORKDIR /app
# Copy the server file into the container
COPY server.js .
# Expose port 3001
EXPOSE 3001
# Run the Node.js server
CMD ["node", "server.js"]
```
- `Dockerfile.sender` is as following:
```
# Use a base image
FROM node:latest
# Set the working directory
WORKDIR /app
# Copy the sender file into the container
COPY sender.js .
# Run the message sender
CMD ["node", "sender.js"]
```
3. After making dockerfiles, we build `Docker image` from Dockerfiles with the following commands:```
$ docker build -t server:v0.1 -f Dockerfile.server .
$ docker build -t sender:v0.1 -f Dockerfile.sender .
```
4. Then we run the image inside the Docker container with the following commands:
```
$ docker run -d -p 3001:3001 --name server server:v0.1
$ docker run -d --name sender sender:v0.1
```
5. We write script file to collect Docker containers logs into one `*.json` file. After running previous images in the Docker containers, we run `collect_logs.sh` script with the following command:
```
$ ./collect_logs.sh
# then we get following answer from the terminal
$ Logs collected and saved to logs.json
```6. Then we go inside the `logs.json` file to check the logs output:
```diff
- To Do:
- As you've seen currently logs are being gathered only for one container and other container logs are not being tracked. So script source should be reconfigured to handle the issue
```## [Reference]()
- [Docker](https://docs.docker.com/) - official Docker documentation which shows how to make `image` file and run that particular image inside the `container`.