简体   繁体   English

将 DDEV 数据库挂载到主机文件系统而不是在 docker 卷内

[英]Mount DDEV database to host filesystem instead of inside docker volume

I've a project with a large database (more or less 50GB) and since i have to run also other projects with docker/ddev this could be a problem, i for sure can make the size of the docker disk but i wanted to know if it's possible for a certain project keep the database outside docker...我有一个带有大型数据库(或多或少 50GB)的项目,并且由于我还必须使用 docker/ddev 运行其他项目,这可能是一个问题,我肯定可以制作 docker 磁盘的大小,但我想知道如果某个项目有可能将数据库保留在 docker 之外...
With plain docker (docker-compose) projects i keep a "data" folder that's not inside docker, i would like to do more or less the same thing with ddev if it's possible.对于普通的 docker (docker-compose) 项目,我保留了一个不在 docker 内部的“数据”文件夹,如果可能的话,我想用 ddev 或多或少地做同样的事情。
Now i'm on OSX, but if it's possible also in Win10 it would be great.现在我在 OSX 上,但如果在 Win10 中也有可能,那就太好了。
Thanks!谢谢!

ddev used to mount the database onto the host with a bind-mount, but docker has quite a number of problems with that, especially on Windows. ddev 过去使用绑定挂载将数据库挂载到主机上,但是 docker 有很多问题,尤其是在 Windows 上。 It worked OK on mac and Linux though, didn't work well on Docker Toolbox on Win10 Home.它在 mac 和 Linux 上运行良好,但在 Win10 Home 上的 Docker Toolbox 上运行不佳。 Docker volumes are more reliable for interacting, and faster, because they're on a linux volume. Docker 卷在交互方面更可靠且速度更快,因为它们位于 linux 卷上。

However, you could make a .ddev/docker-compose.bindmountdb.yaml with contents like this, which basically switches back to the old approach, and bind-mounts the database into the project's .ddev/db directory.但是,您可以使用这样的内容制作.ddev/docker-compose.bindmountdb.yaml ,这基本上切换回旧方法,并将数据库绑定挂载到项目的 .ddev/db 目录中。

version: "3.6"

services:
  db:
    volumes:
    - type: "bind"
      source: "./db"
      target: "/var/lib/mysql"

Another option, of course, is to run a MySQL/MariaDB server on your host computer, for that huge database.当然,另一种选择是在您的主机上运行 MySQL/MariaDB 服务器,用于那个庞大的数据库。 Your project could then access the database on the host using the hostname "host.docker.internal".然后,您的项目可以使用主机名“host.docker.internal”访问主机上的数据库。 This gets you into the business of running and managing your own database server on the host, but with a huge database it might be appropriate.这使您可以在主机上运行和管理自己的数据库服务器,但对于庞大的数据库,这可能是合适的。 You could also run the db server elsewhere on your local network, which is the same basic idea;您也可以在本地网络的其他地方运行 db 服务器,这是相同的基本思想; the db server just has to be accessible from inside the web container. db 服务器只需要可以从 web 容器内部访问。 In either of these cases, you could use omit_containers: [db] and just not use the db container at all.在这两种情况中的任何一种情况下,您都可以使用omit_containers: [db]而根本不使用 db 容器。

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

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