简体   繁体   English

如何将Docker卷安装到我的主机OS(macOS)?

[英]How to mount a Docker volume to my host OS (macOS)?

I persist container's data to a volume (not a bind mount ) and I wonder how I can inspect this data later. 我将容器的数据持久化到一个 (而不是绑定安装 )上,我想知道以后如何检查这些数据。 For example, let's say that I use something like this to run a WordPress site: 例如,假设我使用类似的方法来运行WordPress网站:

docker-compose.yml : docker-compose.yml

services:
  wordpress:
    volumes:
      - wordpress-files:/var/www/html

volumes:
  wordpress-files:

Is it possible to start another container (based on Alpine or something) that would mount the same volume and also expose it to my host OS (macOS – I'm using Docker for Mac)? 是否可以启动另一个容器(基于Alpine或其他),该容器将装载相同的卷并将其公开给我的主机操作系统(macOS –我正在使用Mac的Docker)? Something like this (pseudocode): 这样的东西(伪代码):

services:

  wordpress:
    image: wordpress
    volumes:
      - wordpress-files:/var/www/html

  wordpress-files-inspector:
    volumes:
      - wordpress-files:/tmp:host

volumes:
  wordpress-files:

It's possible to exec into a temporary container but I'd like to make the files available to my local filesystem so that I can use my local tools to browse them. 可以执行到临时容器中,但是我想使文件可用于本地文件系统,以便可以使用本地工具浏览它们。 Note that primarily, the files need to live in a named volume (for performance and other reasons) so it cannot be a bind mount like ./my-local-path:/var/www/html . 需要注意的是主要的文件需要住在一个叫体积(性能和其他原因),所以它不可能是一个绑定安装像./my-local-path:/var/www/html

Why don't you just use samba? 您为什么不只使用samba? Like that: 像那样:

services:

  wordpress:
    image: wordpress
    volumes:
      - wordpress-files:/var/www/html

  wordpress-files-inspector:
    image: dperson/samba
    command: sh -c "samba.sh -s \"mount;/mount\""
    volumes:
      - wordpress-files:/mount

volumes:
  wordpress-files:

You can inspect IP address of the wordpress-files-inspector container later (or set the container with static ip) and mount it into your host OS. 您可以稍后wordpress-files-inspector容器的IP地址(或使用静态ip设置该容器)并将其安装到主机OS中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM