A
A
Anton Mikhailov2020-09-09 10:49:11
Docker
Anton Mikhailov, 2020-09-09 10:49:11

Docker locks mounted volume?

There is the following situation:
- The spring-boot service writes logs through logback to the output.log file
- Log rotation is configured in logback and it periodically empties output.log, dropping logs into archive files specified in the rotation policy. That is, the output.log itself is such a temporary buffer with the latest log
- All this works great: https://www.youtube.com/watch?v=hrWmfC3y9zM
- But if we mount the folder with logs from the container outside (and we need this is for reading by a third-party utility), then everything breaks down - output.log stops being automatically cleared, grows indefinitely, and the archive files specified in the rotation policy are not created at all. This happens even when nobody reads the file from this directory on the host machine.

Conditionally like this
1) This is inside the container with the service

/app/
    |-> service.jar


buffer log is written here:
/app/logs/
         |-> output.log


rotation files recline here
/app/
     |-> out1.log
     |-> out2.log


mounted outside like this:
volumes:
  - /LOGS:/app/logs:rw

2. The second container that reads the logs is mounted like this:
volumes:
  - /LOGS:/var/log

But the reading container has nothing to do with it. Even when it is stopped, the file is locked. That is, for blocking, it is enough just to mount a folder in the first source container with the service

. Is this some kind of feature of docker volumes? And is there any way to bypass it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
chupasaurus, 2020-09-09
@chupasaurus

By setting a file as a volume, the kernel will hold a file descriptor to it as long as the container is alive (it will release it only after the server is rebooted, until the Docker daemon is running). Mount directories with logs if you want normal rotation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question