Docker应用程序中的数据库
我有一个Docker Web应用程序与我已经build立的数据库:
-v /home/stephane/dev/php/learnintouch/docker/mysql/data:/usr/bin/mysql/install/data
它工作正常,但我想知道这是否是推荐的方式去。
对于我看,我们也可以通过给主机上的名字而不是绝对path创build一个命名卷:
-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"
使用已定义主机path的命名卷(或者更具体地说是使用Docker Engine volume API创build的卷)与您使用的方法相比没有多大优势。 从技术上讲,创build一个新的容器是“容易”的,但只是因为你不再需要记住path。 您还可以使用卷API独立于应用程序容器来“pipe理”卷,但使用docker容器API同样也很容易。
如果您坚持要使用绝对主机path创build命名卷,则需要使用卷驱动程序。 我会build议本地坚持。 这很简单,安装和运作良好。