I'm new to Docker and have a question about leaving volume as default. Here is my Dockerfile
:
FROM ubuntu:18.04
WORKDIR /root
RUN apt-get update && apt-get install -y \
curl \
gnupg2 \
git
CMD ["/bin/bash"]
I run the container as follows docker container run -it gcp:1.0
.
The problem comes when I'm trying to inspect the running container:
$ sudo docker inspect bfa3a5495364
"Image": "sha256:6edaefc071a94e18d26de68ca90d9fbe11267c32510d1c3683c236d0b4195df7",
"ResolvConfPath": "/var/lib/docker/containers/bfa3a54953646bee1effccc956c2448fb403083e8faed35afd76a635cd2ccb84/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/bfa3a54953646bee1effccc956c2448fb403083e8faed35afd76a635cd2ccb84/hostname",
"HostsPath": "/var/lib/docker/containers/bfa3a54953646bee1effccc956c2448fb403083e8faed35afd76a635cd2ccb84/hosts",
"LogPath": "/var/lib/docker/containers/bfa3a54953646bee1effccc956c2448fb403083e8faed35afd76a635cd2ccb84/bfa3a54953646bee1effccc956c2448fb403083e8faed35afd76a635cd2ccb84-json.log",
...
"Mounts": [],
...
So since Mounts
is empty it does not provide any information about the actual volume location which in that case was selected by default. I also tried to print all volumes:
$ sudo docker volume ls
DRIVER VOLUME NAME
shows no volume.
QUESTION: How to determine volume location that was selected by default?
Here is an answer from the docs:
By default all files created inside a container are stored on a writable container layer. This means that:
The data doesn’t persist when that container no longer exists, and it can be difficult to get the data out of the container if another
process needs it. A container’s writable layer is tightly coupled to the host machine where the container is running. You can’t easily move the data somewhere else. Writing into a container’s writable layer requires a storage driver to manage the filesystem. The storage driver provides a union filesystem, using the Linux kernel. This extra abstraction reduces performance as compared to using data volumes, which write directly to the host filesystem.
Docker has two options for containers to store files in the host machine, so that the files are persisted even after the container stops: volumes, and bind mounts. If you’re running Docker on Linux you can also use a tmpfs mount. If you’re running Docker on Windows you can also use a named pipe.
Keep reading for more information about these two ways of persisting data.
see this