- [Instructor] Let's first use the Docker volume LS command
to see what volumes we may have already on this host.
As you can tell, there's actually quite a few
volumes out here.
Some of them have very readable names,
human readable names, like nginx vol
or ucp note certs or web vol.
Others have very long, unique identifiers
that were automatically created when the Docker
volume was created.
If we clear the screen and just type docker volume
and press enter, you can see it's from here that we can
not only list volumes, but also prune out unused volumes,
remove specific volumes, and yes, do an inspect,
on those volumes to learn more about them.
For example, let's inspect this volume called web-vol,
which honestly, I don't know what it's doing there.
And I'll pipe that to more.
And, as you can see, it tells us a little bit about this.
It tells us the specific mountpoint,
so where in our file system,
in var lib docker slash volumes.
Oh, we get a permission denied.
Actually, we're going to need to su here to root.
And now let's try that again,
var lib docker volumes.
So, this is where the mountpoint for this volume is located.
You can see the volume name is web vol.
And it's a local volume.
If we do an LS here in this folder,
or LS minus L, pipe that to more,
you can see here is the web vol.
And it's actually a directory.
So now we can cd into web vol.
Do a LS minus L.
And there's an underscored data.
Do ls minus l inside that.
And this volume's actually empty.
Nothing has been created yet in this volume.
And that makes me wonder.
What other volumes are available to us?
And do they have any data?
So let's cd into, for example, node certs.
Do an ls and we'll cd into data.
Ls, and here we go.
Here is actually some data.
These are the node certificates for the ucp web server.
So you can see these volumes are actually real files
on discs that have human, readable files inside.
But then they can be mounted by one or multiple containers
on the host.
So let's say that we wanted to create a new volume.
And run a new container at the same time.
I'll do a docker container run.
And let's mount ourselves a new volume here.
And what you have to do is specify the source
of the volume.
And in our case, we can just give it a name,
like david vol for David's volume.
And then we do a comma here and we type target.
And the target equals, and I'm sorry,
this back here should have an equals instead of a colon.
So the target, just like the source,
is going to equal, and it's going to actually mount
this volume inside the target location
inside the container.
So, if we do nginx as our container,
which is the web server,
what should happen is inside the slash app folder,
this volume that we're creating
called david dash vol is mounted.
So let's push enter on that.
It tells us it downloaded the newer image
for nginx, but what did we forget here?
We forgot the minus D to start this up as a daemon.
So I'm going to do a control C here,
and let's do an up arrow.
We'll add the minus D right here after the run.
And there we go.
So we started up, we spawned up this container.
I'm going to do a Docker ps.
There is the nginx daemon running right there.
And if we do
a Docker container inspect on nginx,
let's actually get the name of it.
Docker container inspect.
And the name of this container,
or the container ID, is starting with zero four zero.
And that flew by really quickly.
If we scroll up a little bit,
let's look for this volume that was
actually created when we started this container.
Here we go, here are the mounts.
The type was a volume called David vol.
And the source is going to be right here,
var lib docker volumes David dash vol slash data,
which we looked at just a minute ago.
This var lib docker volumes folder.
And then the destination is going to be
this slash app folder inside the web server itself.
Now, if we do docker volume inspect
on David dash vol,
we get some more detail about it.
Again, we get the mountpoint.
We see that it's a local volume.
It has a name, David dash vol.
And then at this point, we could, actually,
start up another container.
Perhaps this new container has a different name,
and it could also share access to this volume
that we created.
That way, all the containers that start
that use this volume are able to
have access to the same persistent data.
So that's what you need to know about
Docker container volumes.
The most recommended way to store your persistent data,
not inside a container, but outside of the container,
on the local Docker host file system.
I encourage you to spend some time playing
with Docker volumes and learn how you can
instantiate multiple containers that all have
access to the same local Docker volume.