Welcome to the Linux Foundation Forum!

Chapter 09: Persistent data with UnionFS?

Hello everyone!

Is it possible to mount persistent volumes inside a conatiner using UnionFS? Let me explain what I'm training to archive here a little further:

Let's assume the following:

  • On my host machine, I have a directory /mnt/share and a file called file_on_host.txt in that directory.
  • Furthermore, I have a container image that has a directory /share and a file called file_in_container.txt in that directory.

Now:
Is it possible to mount /mnt/share from my host machine inside a container under /share in such a way that both files are visible in the container? And that changes to either file are persistently stored in /mnt/share on my host machine. So when I start the container again, both files are "up to date"?

When I run:
docker run --volume="/mnt/share:/share" -it my/image sh

I can only see the file file_on_host.txt in the container, but not file_in_container.txt.

In chapter 09 in section "Storage and Docker Volumes" it says:

Persistent volumes are not managed by UnionFS, ...

Is there a way to archive, what I want to do anyways?

Kind regards,
Andreas

Answers

  • chrispokorni
    chrispokorni Posts: 1,603

    Hi @schuam,

    The UnionFS is a storage mechanism used to implement container image layers.

    The mounting of volume, however, in a container at runtime follows the expected mounting behavior, where the source overwrites (temporarily for the duration of the mount) the destination. That is the reason you only see the host file after the mount, but not the container file. Running the container without a mount would reveal the container file.

    A solution, which I have not tried, to install unionfs-fuse tool in the container, and create a union directory between a container directory and a mounted directory, in a similar way as explored by the lab exercise. A direct mount, however, would just overwrite the container file with the host file.

    Regards,
    -Chris

  • schuam
    schuam Posts: 9

    Hi @chrispokorni,

    thank you very much for your answer and the hint to the unionfs-fuse that was use in one of the labs. I haven't gotten to try it out, but I will as soon as I find the time to do so.

    Best regards,
    Andreas

Categories

Upcoming Training