Is there a way to access the temporary filesystem in use during a docker build step?
My particular scenario involves a basic Dockerfile:
FROM ubuntu:22.04
...
RUN long_running_script.sh
...
where long_running_script.sh
is a third party script that dumps any issues it encounters whilst running to a file log.txt
and not to stdout
.
Is there any way for me to view log.txt
whilst that (multiple hour long) script is being run, i.e. whilst that build step is in progress?
2
Answers
In my version of docker (24.0.6 on Ubuntu 22.04) all new files in a container filesystem are located at
/var/lib/docker/overlay2/CONTAINERID/diff
.In other versions, or if manually configured to use a different filesystem driver, this will be in a different location (e.g.
/var/lib/docker/btrfs/
, see https://docs.docker.com/storage/storagedriver/select-storage-driver/ for all options)The
CONTAINERID
of the in progress build layer is hidden (as this build layer does not appear as a container indocker ps -a
). Nevertheless thelog.txt
can be found by either guessing the correctCONTAINERID
, or if all other containers than the build are stopped it will be the newest container (identified withls -t /var/lib/docker/overlay2/ | head -1
)you can add extra bash
wrapper.sh
script like(solution from https://stackoverflow.com/a/12358911/6515755)
and run in your docker build