I'm completely new to the Docker world and no matter where ever I searched for it, it seems like there's no applicable solution. I know many questions asks about the same issue surrounding logging, yet I could not find a basic, detailed solution that will help me to apply it myself.
tldr;
I currently have a .NET Core 5.0 Console Application that creates a log file using log4net
to a local directory. I want to transfer the application to run through a Windows-based
docker container and to access the log
file while/after it ran to see its results.
I saw the docker documentation | volumes yet could not understand how is it possible to define and later on access the log file.
Is this the way to do it? what should I define differently on my application?
Probably it's not about changing anything in your application, you just need to identify the directory where your logs are stored in the container and attach a volume or bind a mount to it on the host part. So, you can either:
Create a volume and during "docker run" associate it with a directory inside the container where your logs are stored. Volumes can be managed using Docker, which makes it a preferred option. By leveraging them you can e.g. type "docker inspect some-volume-name" to find out where in the host's file system you can see the files from the volume, your logs in this case.
Make a bind mount, which means you are mapping a directory from a host to a directory in a container. This option is pretty straightforward, but you are losing out on all the volumes' features.
Path with volume
Creating a docker volume.
docker volume create logs-from-net-app
Inspecting the volume to find out where you can find its contents.
docker volume inspect logs-from-net-app
Attaching it to the container.
docker run --mount type=volume,source=logs-from-net-app,target=//c/path/to/logs "hello-world"
Path with mounting bind
Making a bind mount during docker run
docker run --mount type=bind,source=C:\logs,target=//c/path/to/logs "hello-world"