iScsc / blog.iscsc.fr

GNU General Public License v3.0
0 stars 7 forks source link

Add files via upload (docker volume article) #28

Closed FireFrozen94 closed 1 month ago

FireFrozen94 commented 4 months ago

this article plain to explain how to use bind mounts in docker, in the particular example of building a log system

ctmbl commented 3 months ago

hey @FireFrozen94 if you see this I've updated a bit the article I tjink it is ready for publishing πŸ‘

FireFrozen94 commented 3 months ago

Yay let's gooo

Le sam. 13 avr. 2024, 06:07, ClementMabileau @.***> a Γ©crit :

hey @FireFrozen94 https://github.com/FireFrozen94 if you see this I've updated a bit the article I tjink it is ready for publishing πŸ‘

β€” Reply to this email directly, view it on GitHub https://github.com/iScsc/blog.iscsc.fr/pull/28#issuecomment-2052534015, or unsubscribe https://github.com/notifications/unsubscribe-auth/BAOG7HYVKJXSHQKN3LH2L2TY5BEKNAVCNFSM6AAAAABDRM4S3KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJSGUZTIMBRGU . You are receiving this because you were mentioned.Message ID: <iScsc/blog. @.***>

ctmbl commented 2 months ago

@atxr tks for your comments, when I read them I got the feeling that you were putting the finger where it huts πŸ˜†

But that's also for the best, to be honest I knew I was missing something about the distinction between volumes/bind mounts, you just gave me the opportunity to enlighten it and learn a bit more!

So let's dive into it (with further research and reading from me)!

DISCLAIMER:
What I expose here you might have already understood but it wasn't clear to me so I'll write it anyway πŸ™‚

TLDR

What we're talking about in this blog aren't volumes at all (even if we use --volume) they are bind mounts, we're just naming them volumes because we're confusing both.

Volumes are not only managed by -v and bind mounts not only managed by --mount.
Flags names and usage are just very very confusing

Examples with -v but similar syntax is possible with --mount:

You'll see that even in docker's doc the naming is confusing

Differences between -v and --mount behavior As opposed to bind mounts, all options for volumes are available for both --mount and -v flags. Volumes used with services, only support --mount.

WTF

Detailed explanation

Actually there are 3 ways of sharing data in docker:

Named volumes

They are a space which exists outside of the container, managed by docker (exist in /var/lib/docker/volumes but you should never write to it form host), and survives containers death.
They have a name.

Named volumes are created either with the docker volume subcommand or with docker run -v <some new volume name>:</path/in/cont> or similar with --mount syntax

about docker volume

about -v in volumes doc:

-v or --volume: Consists of three fields, separated by colon characters (:). The fields must be in the correct order, and the meaning of each field isn't immediately obvious.

  • In the case of named volumes, the first field is the name of the volume, and is unique on a given host machine. For anonymous volumes, the first field is omitted.

also here at Named Volumes section

Anonymous volumes

They are volumes too, only we don't give them a name.
Their only interest (to my understanding) is to share space across containers, because they have no name they cannot be easily reused.

They are created with docker run -v <path/in/cont> and then referred to (because they have no name) and shared with another container with docker run --volumes-from <first container id> or similar with --mount syntax

about their creation with -v:

-v or --volume: Consists of three fields, separated by colon characters (:). The fields must be in the correct order, and the meaning of each field isn't immediately obvious.

  • In the case of named volumes, the first field is the name of the volume, and is unique on a given host machine. For anonymous volumes, the first field is omitted.

example of --volumes-from

Bind mounts

Bind mounts are actually what we describe in the article, they are a file or folder existing on host (at another path than /var/lib/docker/*) that is shared with the container, they can also be shared across containers because they can be mounted several time (but I don't know if this is a good practice honestly).

They are created with docker run -v <path/to/host>:<path/to/cont> or similar with --mount syntax.

about -v in bind mounts doc:

-v or --volume: Consists of three fields, separated by colon characters (:). The fields must be in the correct order, and the meaning of each field is not immediately obvious.

  • In the case of bind mounts, the first field is the path to the file or directory on the host machine.

Ressources

docker doc:

Other sources:

ctmbl commented 2 months ago

@atxr What I've written above is almost a blog post in itself ahah

Sorry for the extensive writing, I just wanted to avoid any possible misunderstanding which would have necessarily lead to pointless debates. If you don't feel like digging in the details just read the TLDR section it should be enough to explain what was missleading us in my previous version of the article.

In the end it was @FireFrozen94 who was right to speak about bind mounts in his article, they are nothing alike volume and I was wrong to confuse them.
We can confuse --volume and --mount but we can't confuse the concepts of volumes and bind mounts

I'll soon propose a version that should satisfy everyone

atxr commented 2 months ago

Don't worry I didn't dig dip enough to get all the details you just highlighted in your TLDR I just spotted there was some misunderstanding about mounts and volumes that were "thrown under the carpet" :broom: I'm glad it helped! Looking forward the fix! :waffle:

ctmbl commented 2 months ago

@atxr @ZynoXelek I finally found some time to propose an up-to-date and confusion-less (I hope) version of the article

Sorry @FireFrozen94 for the previous modifications which were partially wrong, my bad πŸ˜“

ctmbl commented 1 month ago

tks @atxr could You approve now? :slightly_smiling_face: