Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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


Image

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


Image

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:


Image

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