Open kovax opened 2 years ago
@sevdokimov it would be great to know if you support this proposal. I can do all the changes to the poms, but as I stated above some changes to the file selection would be needed that I am not qualified to do unfortunately.
@kovax , Thank you. I definitely support this proposal. It's a good idea. But, unfortunately, I'm not familiar with Docker. How can I get the list of volumes from java code? Or how we can pass the list of volumes to the application configuration? Sorry for the delay.
@sevdokimov sorry for the long slience. I can definitely do all the docker changes.
How can I get the list of volumes from java code?
You cannot do that, an application in a docker container only sees the volumes (i.e. files, directories) shared from the host. That is what I tried to explain in my original post. So instead it shall be possible to configure the logviewer to scan a specific directory only instead of leting the user the select one. This is the change I would need you to do.
Or how we can pass the list of volumes to the application configuration?
I plan to use Google JIB to build the docker image, which puts the full application into /app
directory (see JIB FAQ: Where is the application in the container). So following this approach, the logviewer image shall expose the /app/externalLogs
directory as a volume.
I agree with kovax. Its good idea. But dockers cant communicate in docker-compose and look files each other. But maybe u can use configuration in docker-compose like this: log-viewer: image: log-viewer networks: core_net: ipv4_address: 172.19.1.1 restart: always volumes:
And in your confg file: logs = [ { path: "/opt/logs/**" } ]
With volume mapping, you could make a docker container where people would map their logs into the docker container for the log viewer to see. Similar to the suggestion above - I think you could craft a docker image with this app that worked, using env variables probably
There is no need for additional development @sevdokimov, I created a Dockerfile and a docker compose file that packages the software and lets them pass in their own config file, and passes in relevant logs: Steps: 1) Download a release 2) cd into the release's folder 3) Create the following Dockerfile into this folder:
# Select a image that includes java 8
FROM openjdk:8-slim-buster # this is the base image
# Copy files from log-viewer release
COPY ./lib /lib
COPY ./logviewer.sh /
# expose the port the the service will run on
EXPOSE 8111
# command that is executed when the docker container starts
CMD ["/logviewer.sh"]
Then create the following docker-compose file in the same directory as before
version: "3"
services:
log-viewer:
image: sevdokimov/log-viewer
build: # This builds the image - if this image was placed on Docker Hub, you could remove this and use the username/image:tag to pull the pre-built image
context: .
dockerfile: Dockerfile
configs:
- config.conf # This passes the config defined below into the container - this is mandatory as we do not copy in the default config
volumes:
- /var/log:/var/log # This can be modified to pass in whatever log directories into the container. The right side is the path inside the docker container and should match your config file
ports:
- 8111:8111 # This can be remapped to whatever port you would like to expose on the left. The right, with the above dockerfile, must remain 8111
configs:
config.conf: # This must be this name as it is passed in as that file name
file: ./config.conf # This is the path to the config file for this log-viewer docker container
Then run:
$ docker compose up -d --build
Or if there ends up being a docker hub image run:
$ docker compose up -d
@nklisch thanks for the tip. Following your suggestions I did these steps to get image in our private repository, and use it for my dokcer-compose project:
Download a release and cd into the folder
Create this Dockerfile. It copies the log-viewer app to /app
folder
# Select a image that includes java 8
FROM openjdk:11
# Copy files from log-viewer release
COPY ./lib /app/lib
COPY ./logviewer.sh /app/.
# expose the port the the service will run on
EXPOSE 8111
# command that is executed when the docker container starts
CMD ["/app/logviewer.sh"]
Edit logviewer.sh as I prefer config files in a separate directory, and renamed the file so it will not collide with others:
-Dlog-viewer.config-file=$SCRIPT_DIR/config/logviewer.conf
Build image with the release tag and the docker repository url:
$ docker build -t myprivate.dockerrepo.com/sevdokimov-logviewer:1.0.3 .
Login to repository: $ dokcer login
Push image to repository: $ docker push myprivate.dockerrepo.com/sevdokimov-logviewer:1.0.3
Add service configuration to docker-compose.yml
/app/logs
shared volumeconfig/logviewer.config
file is in made available in the /app/config
shared volumeservices:
logviewer:
image: myprivate.dockerrepo.com/sevdokimov-logviewer:1.0.3
volumes:
- ./log:/app/logs
- ./config:/app/config
ports:
- 172.18.0.1:8111:8111/tcp
restart: always
labels:
- "traefik.enable=false"
Restart docker-compose project
docker-compose down; docker-compose pull; docker-compose up -d
Oh, I did not want to close it :). I guess some weird keyboard shortcut did it by accident.
I would also love to have an official docker image available for log-viewer. Is there any chance the image could be PR'd and the relevant docs added?
If others aren't available to do so then I'd be happy to put together a PR for this, but I'd like to give @kovax / @nklisch the opportunity to submit their own work first if they'd like to.
@enpaul please go ahead, unfortunately (or fortunately) I am a bit busy to be able to contribute a PR, but I would be happy to review yours.
Made my own based on this: https://github.com/yunbaoguan/log-viewer (https://hub.docker.com/r/yunbaoguan/log-viewer)
I use docker-compose to setup applications, and it would be great if I could use logviewer as an independent container. I would be happy to help to setup this feature.
The pom.xml example bellow is from my open source project showing how to use google jib plugin: https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin
Apps running in a docker container only have access to the files of the host system through shared volumes. This means that browse-and-select log files feature will not work. Instead the logviewer should scan a specific directory (e.g.
/app/externalLogs/
) and expose this to the hosts (see<volumes>
section). When I build my docker-compose project I configure my apps to share the logs with the hosts in a single directory, which means I can configure logviewer container to access that single directory through its shared volume.