Using docker volume to place the log file on a central location

If you run your application as a MicroService in a Docker file you need to think about the place of the log file. To place the log file in the docker file itself is not a good idea, the docker file, which is normally not that big, is growing dramatically and next to that this file is copied everywhere including the log file. So: not good!. An option is using ElasticSearch for pushing the logfiles to a central location. Another option is using Docker Volumes to place the logfiles on a central location of the Docker Host.

Docker Volume

According to : Docker Volumes is the preferred mechanism for persisting data generated by or used by a Docker containers. A docker volume mounts a directory in your container to a directory on the Docker Host. Volumes are managed by the Docker CLI and are supported on both Windows and Linux.



docker run -d --name mygeopapi -p 80:80 -v "=/var/log:/app/log" --privileged=true mygeoapi:latest

-d run as deamon

--name name off the docker container

-p ports available on the outside off the container

-v volume, the first part is the directory on the server the second part the directory in the docker image

--privileged=true needed for write access to the directory

:latest the tag of the image on which the container is build, latest takes the lates available image.

Container Directory

Maybe a litle obvous but how do you create a container in your Docker Image. This is done by adding a Directory in your solution. Normally you use this to organise your solution and place your code files in it and a namespace is created. So in this example you create a directory 'log' in your solution wich can be empty and by that a directory 'log' is created in your Docker Container wich can be mapped to a local log directory, normally /var/log.

Be aware!!!

To save you some time, like a wasted some. If you run your container on Linux: LINUX IS CASE SENSITIVE.




Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!