我有一个 Docker Web 应用程序及其已设置的数据库:
-v /home/stephane/dev/php/learnintouch/docker/mysql/data:/usr/bin/mysql/install/data
它工作正常,但我想知道这是否是推荐的方法。
据我所知,我们还可以通过提供名称而不是主机上的绝对路径来创建命名卷:
-v learnintouch-data:/usr/bin/mysql/install/data
但是,我如何将卷名 learnintouch-data 与位于 /home/stephane/dev/php/learnintouch/docker/mysql/data
的主机位置相关联?
这是我当前的 docker-compose.yml
文件:
learnintouch.com-startup:
image: stephaneeybert/learnintouch.com-startup
container_name: learnintouch.com-startup
ports:
- "80:80"
links:
- mysql
- redis
- nodejs-learnintouch
nodejs-learnintouch:
image: stephaneeybert/nodejs-learnintouch
container_name: nodejs-learnintouch
ports:
- "9001:9001"
links:
- redis
mysql:
image: stephaneeybert/mysql:5.6.30
container_name: mysql
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=root
volumes:
- "/home/stephane/dev/php/learnintouch/docker/mysql/data:/usr/bin/mysql/install/data"
redis:
image: stephaneeybert/redis:3.0.7
container_name: redis
ports:
- "6379:6379"
最佳答案
使用具有已定义主机路径的命名卷(或更具体地说,使用 Docker 引擎卷 API 创建的卷)与您使用的方法相比没有太大优势。从技术上讲,创建新容器“更容易”,但这只是因为您不再需要记住路径。您还可以使用卷 API 独立于应用程序容器“管理”卷,但使用 docker 容器 API 也同样容易。
如果您坚持要创建具有绝对主机路径的命名卷,则需要使用卷驱动程序。我会建议本地坚持。安装非常简单,运行良好。
关于mysql - Docker 应用程序中的数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41398143/