Docker has been widely adopted and is used to run and scale applications in production. Additionally, it can be used to start applications quickly by executing a single Docker command.

Docker已被广泛采用,并用于在生产中运行和扩展应用程序。 此外,它可以通过执行单个Docker命令来快速启动应用程序。

Companies also are investing more and more effort into improving development in local and remote Docker containers, which comes with a lot of advantages as well.

公司还投入越来越多的精力来改善本地和远程Docker容器的开发,这也具有很多优势。

You can get the basic information about your Docker configuration by executing:

您可以通过执行以下命令获取有关Docker配置的基本信息:

$ docker info...Storage Driver: overlay2Docker Root Dir: /var/lib/docker
...

The output contains information about your storage driver and your docker root directory.

输出包含有关存储驱动程序和docker根目录的信息。

Docker映像和容器的存储位置 (The storage location of Docker images and containers)

A Docker container consists of network settings, volumes, and images. The location of Docker files depends on your operating system. Here is an overview for the most used operating systems:

Docker容器由网络设置,卷和映像组成。 Docker文件的位置取决于您的操作系统。 以下是最常用的操作系统的概述:

  • Ubuntu: /var/lib/docker/

    Ubuntu: /var/lib/docker/

  • Fedora: /var/lib/docker/

    Fedora的: /var/lib/docker/

  • Debian: /var/lib/docker/

    Debian: /var/lib/docker/

  • Windows: C:\ProgramData\DockerDesktop

    Windows: C:\ProgramData\DockerDesktop

  • MacOS: ~/Library/Containers/com.docker.docker/Data/vms/0/

    MacOS: ~/Library/Containers/com.docker.docker/Data/vms/0/

In macOS and Windows, Docker runs Linux containers in a virtual environment. Therefore, there are some additional things to know.

在macOS和Windows中,Docker在虚拟环境中运行Linux容器。 因此,还有一些其他事情要知道。

Mac版Docker (Docker for Mac)

Docker is not natively compatible with macOS, so Hyperkit is used to run a virtual image. Its virtual image data is located in:

Docker与macOS本身不兼容,因此Hyperkit用于运行虚拟映像。 其虚拟图像数据位于:

~/Library/Containers/com.docker.docker/Data/vms/0

~/Library/Containers/com.docker.docker/Data/vms/0

Within the virtual image, the path is the default Docker path /var/lib/docker.

在虚拟映像中,该路径是默认Docker路径/var/lib/docker

You can investigate your Docker root directory by creating a shell in the virtual environment:

您可以通过在虚拟环境中创建外壳来调查Docker根目录:

$ screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty

You can kill this session by pressing Ctrl+a, followed by pressing k and y.

您可以通过按Ctrl + a ,然后按ky终止此会话。

Windows版Docker (Docker for Windows)

On Windows, Docker is a bit fractioned. There are native Windows containers that work similarly to Linux containers. Linux containers are run in a minimal Hyper-V based virtual environment.

在Windows上,Docker有点分散。 有些本机Windows容器的工作方式与Linux容器类似。 Linux容器在最小的基于Hyper-V的虚拟环境中运行。

The configuration and the virtual image to execute linux images are saved in the default Docker root folder.

执行Linux映像的配置和虚拟映像保存在默认Docker根文件夹中。

C:\ProgramData\DockerDesktop

C:\ProgramData\DockerDesktop

If you inspect regular images then you will get linux paths like:

如果您检查常规映像,则将获得linux路径,例如:

$ docker inspect nginx...
"UpperDir": "/var/lib/docker/overlay2/585...9eb/diff"
...

You can connect to the virtual image by:

您可以通过以下方式连接到虚拟映像:

docker run -it --privileged --pid=host debian nsenter -t 1 -m -u -i sh

There, you can go to the referenced location:

在这里,您可以转到参考位置:

$ cd /var/lib/docker/overlay2/585...9eb/
$ ls -lahdrwx------    4 root     root        4.0K Feb  6 06:56 .
drwx------   13 root     root        4.0K Feb  6 09:17 ..
drwxr-xr-x    3 root     root        4.0K Feb  6 06:56 diff
-rw-r--r--    1 root     root          26 Feb  6 06:56 link
-rw-r--r--    1 root     root          57 Feb  6 06:56 lower
drwx------    2 root     root        4.0K Feb  6 06:56 work

Docker根文件夹的内部结构 (The internal structure of the Docker root folder)

Inside /var/lib/docker, different information is stored. For example, data for containers, volumes, builds, networks, and clusters.

/var/lib/docker ,存储了不同的信息。 例如,容器,卷,构建,网络和群集的数据。

$ ls -la /var/lib/dockertotal 152
drwx--x--x   15 root     root          4096 Feb  1 13:09 .
drwxr-xr-x   13 root     root          4096 Aug  1  2019 ..
drwx------    2 root     root          4096 May 20  2019 builder
drwx------    4 root     root          4096 May 20  2019 buildkit
drwx------    3 root     root          4096 May 20  2019 containerd
drwx------    2 root     root         12288 Feb  3 19:35 containers
drwx------    3 root     root          4096 May 20  2019 image
drwxr-x---    3 root     root          4096 May 20  2019 network
drwx------    6 root     root         77824 Feb  3 19:37 overlay2
drwx------    4 root     root          4096 May 20  2019 plugins
drwx------    2 root     root          4096 Feb  1 13:09 runtimes
drwx------    2 root     root          4096 May 20  2019 swarm
drwx------    2 root     root          4096 Feb  3 19:37 tmp
drwx------    2 root     root          4096 May 20  2019 trust
drwx------   15 root     root         12288 Feb  3 19:35 volumes

Docker映像 (Docker images)

The heaviest contents are usually images. If you use the default storage driver overlay2, then your Docker images are stored in /var/lib/docker/overlay2. There, you can find different files that represent read-only layers of a Docker image and a layer on top of it that contains your changes.

最重的内容通常是图像。 如果使用默认的存储驱动程序overlay2,则您的Docker映像将存储在/var/lib/docker/overlay2 。 在这里,您可以找到不同的文件,这些文件分别代表Docker映像的只读层和其上包含您的更改的层。

Let’s explore the content by using an example:

让我们通过一个示例来探索内容:

$ docker image pull nginx
$ docker image inspect nginx[{"Id": "sha256:207...6e1","RepoTags": ["nginx:latest"],"RepoDigests": ["nginx@sha256:ad5...c6f"],"Parent": "",..."Architecture": "amd64","Os": "linux","Size": 126698063,"VirtualSize": 126698063,"GraphDriver": {"Data": {"LowerDir": "/var/lib/docker/overlay2/585...9eb/diff:/var/lib/docker/overlay2/585...9eb/diff","MergedDir": "/var/lib/docker/overlay2/585...9eb/merged","UpperDir": "/var/lib/docker/overlay2/585...9eb/diff","WorkDir": "/var/lib/docker/overlay2/585...9eb/work"},
...

The LowerDir contains the read-only layers of an image. The read-write layer that represents changes are part of the UpperDir. In my case, the NGINX UpperDir folder contains the log files:

LowerDir包含图像的只读层。 表示更改的读写层是UpperDir的一部分。 就我而言,NGINX UpperDir文件夹包含日志文件:

$ ls -la /var/lib/docker/overlay2/585...9eb/difftotal 8
drwxr-xr-x    2 root     root    4096 Feb  2 08:06 .
drwxr-xr-x    3 root     root    4096 Feb  2 08:06 ..
lrwxrwxrwx    1 root     root      11 Feb  2 08:06 access.log -> /dev/stdout
lrwxrwxrwx    1 root     root      11 Feb  2 08:06 error.log -> /dev/stderr

The MergedDir represents the result of the UpperDir and LowerDir that is used by Docker to run the container. The WorkDir is an internal directory for overlay2 and should be empty.

MergedDir表示Docker用于运行容器的UpperDirLowerDir的结果。 WorkDir是overlay2的内部目录,应该为空。

Docker卷 (Docker Volumes)

It is possible to add a persistent store to containers to keep data longer than the container exists or to share the volume with the host or with other containers. A container can be started with a volume by using the -v option:

可以向容器添加持久性存储,以使数据保存的时间长于容器的存在,或者可以与主机或其他容器共享卷。 可以使用-v选项以卷启动容器:

$ docker run --name nginx_container -v /var/log nginx

We can get information about the connected volume location by:

我们可以通过以下方式获取有关已连接卷位置的信息:

$ docker inspect nginx_container...
"Mounts": [{"Type": "volume","Name": "1e4...d9c","Source": "/var/lib/docker/volumes/1e4...d9c/_data","Destination": "/var/log","Driver": "local","Mode": "","RW": true,"Propagation": ""}],
...

The referenced directory contains files from the location /var/log of the NGINX container.

引用的目录包含来自NGINX容器的/var/log位置的文件。

$ ls -lah /var/lib/docker/volumes/1e4...d9c/_datatotal 88
drwxr-xr-x    4 root     root        4.0K Feb  3 21:02 .
drwxr-xr-x    3 root     root        4.0K Feb  3 21:02 ..
drwxr-xr-x    2 root     root        4.0K Feb  3 21:02 apt
-rw-rw----    1 root     43             0 Jan 30 00:00 btmp
-rw-r--r--    1 root     root       34.7K Feb  2 08:06 dpkg.log
-rw-r--r--    1 root     root        3.2K Feb  2 08:06 faillog
-rw-rw-r--    1 root     43         29.1K Feb  2 08:06 lastlog
drwxr-xr-x    2 root     root        4.0K Feb  3 21:02 nginx
-rw-rw-r--    1 root     43             0 Jan 30 00:00 w

清理Docker使用的空间 (Clean up space used by Docker)

It is recommended to use the Docker command to clean up unused containers. Container, networks, images, and the build cache can be cleaned up by executing:

建议使用Docker命令清理未使用的容器。 可以通过执行以下操作清除容器,网络,映像和构建缓存:

$ docker system prune -a

Additionally, you can also remove unused volumes by executing:

此外,您还可以通过执行以下操作来删除未使用的卷:

$ docker volumes prune

摘要 (Summary)

Docker is an important part of many people’s environments and tooling. Sometimes, Docker feels a bit like magic by solving issues in a very smart way without telling the user how things are done behind the scenes. Still, Docker is a regular tool that stores its heavy parts in locations that can be opened and changed.

Docker是许多人的环境和工具的重要组成部分。 有时候,Docker通过非常聪明的方式解决问题而又不告诉用户幕后事情是如何做的,有点像魔术。 不过,Docker是一种常规工具,可将重型零件存储在可以打开和更改的位置。

Sometimes, storage can fill up quickly. Therefore, it’s useful to inspect its root folder, but it is not recommended to delete or change any files manually. Instead, the prune commands can be used to free up disk space.

有时,存储空间可能会很快用完。 因此,检查其根文件夹很有用,但不建议手动删除或更改任何文件。 而是可以使用prune命令释放磁盘空间。



I hope you enjoyed the article. If you like it and feel the need for a round of applause, follow me on Twitter.

希望您喜欢这篇文章。 如果您喜欢它并感到需要掌声,请在Twitter上关注我 。

I am a co-founder of our revolutionary journey platform called Explore The World. We are a young startup located in Dresden, Germany and will target the German market first. Reach out to me if you have feedback and questions about any topic.

我是我们的创新旅程平台“ 探索世界”的共同创始人。 我们是一家年轻的初创公司,位于德国德累斯顿,并将首先瞄准德国市场。 如果您有关于任何主题的反馈和问题,请与我联系。

Happy Docker exploring :)

快乐的Docker探索:)



参考文献 (References)

  • Docker storagediver documentation

    Docker Storagediver文档

    Docker storagediver documentationhttps://docs.docker.com/storage/storagedriver/

    Docker storagediver文档https://docs.docker.com/storage/storagedriver/

  • Documentation Overlay filesystem

    文档覆盖文件系统

    Documentation Overlay filesystemhttps://www.kernel.org/doc/Documentation/filesystems/overlayfs.txt

    文档覆盖文件系统https://www.kernel.org/doc/Documentation/filesystems/overlayfs.txt

翻译自: https://www.freecodecamp.org/news/where-are-docker-images-stored-docker-container-paths-explained/

Docker映像存储在哪里? Docker容器路径介绍相关推荐

  1. docker 删除映像_如何在Docker中删除映像和容器

    docker 删除映像 Docker RMI (Docker rmi) docker rmi removes images by their ID. docker rmi通过其ID删除图像. To r ...

  2. Docker将在存储上崭露头角?

    Docker与存储纪实 在容器中运行应用的想法--也作为OS级虚拟化著称--目前来看是一种潮流技术.这种技术的真身可以追溯到大型机时代. 但是在过去的12个月当中,在单一OS中运行多个相隔离的负载的思 ...

  3. 创建自己SQL Server Docker映像

    In this article, we will review how to create custom SQL Server docker images and run the containers ...

  4. Licode Docker映像

    Licode Docker映像 要运行Licode docker容器,您有两个选择: 您可以使用我们提供的Dockerfile构建自己的映像,然后从中运行容器或 您可以直接从Docker Hub中提供 ...

  5. Docker映像和容器之间有什么区别?

    本文翻译自:What is the difference between a Docker image and a container? When using Docker, we start wit ...

  6. 如何在映像更改后升级docker容器

    本文翻译自:How to upgrade docker container after its image changed Let's say I have pulled the official m ...

  7. docker修改镜像的存储位置_云原生存储详解:容器存储与 K8s 存储卷(内含赠书福利)...

    作者 | 阚俊宝  阿里巴巴技术专家 参与文末留言互动,即有机会获得赠书福利! 导读:云原生存储详解系列文章将从云原生存储服务的概念.特点.需求.原理.使用及案例等方面,和大家一起探讨云原生存储技术新 ...

  8. docker数据卷容器卷_如何删除Docker映像,容器和卷

    docker数据卷容器卷 Docker备忘单 (A Docker Cheat Sheet) 介绍 (Introduction) Docker makes it easy to wrap your ap ...

  9. aws ecr_在ECR上推送Spring Boot Docker映像

    aws ecr 在先前的博客中,我们将Spring Boot应用程序与EC2集成在一起. 它是您可以在Amazon Web Services上进行的最原始的部署形式之一. 在本教程中,我们将使用我们的 ...

最新文章

  1. java 挂钩子_挂钩组件
  2. LeetCode 217 Contains Duplicate--python,java解法--set--简单
  3. HttpHandler在IIS中的部署问题(扩展名映射)
  4. CodeForces - 434D Nanami's Power Plant
  5. 面向对象分析与设计小结
  6. mysql delete 会锁表吗_MySQL高压缩引擎TokuDB 揭秘
  7. 领域应用 | 基于知识图谱的警用安保机器人大数据分析技术研究
  8. hadoop SecondNamenode
  9. Word2016Word2019如何取消自动编号
  10. XenApp and XenDesktop 7.15 LTSR CU6发布
  11. DTMF双音多频信号仿真演示系统
  12. php 微信多客服系统,如何使用微信公众平台开发模式实现多客服
  13. 关于猎聘网投递简历后的“已储备”状态
  14. 苹果操作系统 leopard 10.5 (PC破解完全中文安装版,IBM X40安装成功)
  15. Android - 批量发送短信的实现方式
  16. base64编码类源代码(C#)
  17. 统计学 一元线性回归
  18. 计算机键盘可以分为哪几个区,键盘分为哪几个区?分别是什么?
  19. 截止2010年3月25日的流量统计
  20. baked lighting

热门文章

  1. LSP 里式替换原则 c# 1614092345
  2. 窗体控件绑定泛型数组 0104 c#
  3. dj鲜生-26-登陆时-记住用户名的操作
  4. dj鲜生-07-静态文件的成功加载-用户注册的页面
  5. 【mybatis】mybatis自定义动态字段查询,mybatis实现动态字段查询,如果某个条件为null,则不查询某个字段,否则就查询某个字段...
  6. 转自: http://blog.csdn.net/xiaxiaorui2003/article/details/3838631
  7. 以小见大:如何设计注册登录页?
  8. web.py开发web 第一章 Hello World
  9. VC学习笔记:文本图形
  10. 面试:高并发系统设计