确定 运行 容器的卷位置

Determine volume location of a running container

我是 Docker 的新手,对将音量保留为默认值有疑问。这是我的 Dockerfile:

FROM ubuntu:18.04

WORKDIR /root

RUN apt-get update && apt-get install -y \
                      curl \
                      gnupg2 \
                      git

CMD ["/bin/bash"]

我运行容器如下docker container run -it gcp:1.0

当我试图检查 运行ning 容器时出现问题:

$ 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": [],  
...

因此,由于 Mounts 为空,因此它不提供任何有关实际卷位置的信息,在这种情况下,默认情况下选择了该位置。我还尝试打印所有卷:

$ sudo docker volume ls
DRIVER              VOLUME NAME

没有显示音量。

问题:如何确定默认选择的卷位置?

这是来自文档的答案:

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.

this