在docker-compose.yml上复制'docker volume create --name data'命令 [英] Replicate 'docker volume create --name data' command on docker-compose.yml

查看:464
本文介绍了在docker-compose.yml上复制'docker volume create --name data'命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 docker-compose 构建我的容器,我想使用Docker的新卷API,但是我看不到如何。 p>

我想能够说 docker-compos up -d to:




  • 创建一个卷,或者如果已经创建,可以使用它。

  • 使用以前卷容器中的数据创建服务容器。 b $ b

解决方案

首先,您必须使用版本2 Compose文件来使用新的规范来创建和使用命名卷。 撰写文件参考包括您需要知道的所有内容,包括示例。



总结:


  1. 添加版本:'2' docker-compose.yml 的顶部。

  2. 将服务单位放在服务
  3. 将卷单位放在卷下:键。

  4. 当从服务单元引用命名卷时,指定 volumename:/ path 其中 volumename 是在卷下给出的名称:键(在下面的示例中为 dbdata )和 /路径是装入卷的容器内的位置(例如, / var / lib / mysql )。

以下是创建一个命名卷 dbdata 的最小示例,并从 db 服务。

 版本:'2'
服务:
db:
image:mysql
卷:
- dbdata:/ var / lib / mysql
卷:
dbdata:
驱动程序:local


I'm building my containers with docker-compose and I would like to use the new volume API from Docker, but I don't see how to.

I want to be able to say docker-compose up -d to:

  • Create a volume, or use it if already created.
  • Create services containers with data from previous volume container.

解决方案

First of all you must be using a version 2 Compose file to use the new specifications for creating and using named volumes. The Compose File Reference includes all you need to know, including examples.

To summarize:

  1. Add version: '2' to the top of docker-compose.yml.
  2. Place service units under a services: key.
  3. Place volume units under a volumes: key.
  4. When referring to a named volume from a service unit, specify volumename:/path where volumename is the name given under the volumes: key (in the example below it is dbdata) and /path is the location inside the container of the mounted volume (e.g., /var/lib/mysql).

Here's a minimal example that creates a named volume dbdata and references it from the db service.

version: '2'
services:
  db:
    image: mysql
    volumes:
      - dbdata:/var/lib/mysql
volumes:
  dbdata:
    driver: local

这篇关于在docker-compose.yml上复制'docker volume create --name data'命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆