skip to Main Content

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


  1. Chosen as BEST ANSWER

    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 in docker ps -a). Nevertheless the log.txt can be found by either guessing the correct CONTAINERID, or if all other containers than the build are stopped it will be the newest container (identified with ls -t /var/lib/docker/overlay2/ | head -1)


  2. you can add extra bash wrapper.sh script like

    command &
    cmdpid=$!
    tail -f -n +0 logfile &
    wait $long_running_script.sh
    kill $!
    

    (solution from https://stackoverflow.com/a/12358911/6515755)

    and run in your docker build

    RUN wrapper.sh
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search