如何在docker compose中定义常规安装点 [英] how to define a general mount point in docker compose

查看:66
本文介绍了如何在docker compose中定义常规安装点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想定义一个通用的挂载卷-以及我想关联的所有选项-可以在多个服务中重复使用。实际上,我正在开发一个项目,该项目对多个微服务使用相同的源。
这样,可以更轻松地管理和修改卷。

I would like to define a general mount volume - along with all the options I would like to have it associated - that can be reused across multiple services. In fact, I'm developing a project which uses the same source for several microservices. That way, the volume will be simpler to manage and modify.

首先,我使用了旧的方式,利用了 volumes_from

To start off, I used the old way which took advantage of volumes_from:

shared:
  image: phusion/baseimage 
  volumes:
    - ./code:/var/www/html

nginx:
  build: docker/nginx
  ports:
    - "8080:80"
  links:
    - php
  volumes_from:
    - shared

这可行,但是我必须定义一个共享服务以使其工作。从3.0版本开始,可以使用 volumes ,因此我想定义一个常规体积并将其用于我的 nginx 服务,但找不到正确的语法:

This works, but I had to define a shared service to make it work. As of the 3.0 version, volumes can be used, so I would like to define a general volume and use it into my nginx service, but I'm not finding the right syntax:

version: '3.3'

volumes:
  vol_test:
    type: bind
    source: ./code
    target: /var/www/html
    volume:
      nocopy: true

services:
  nginx:
    build: docker/nginx
    ports:
      - "8080:80"
    volumes:
      - vol_test



更新



I' ve发现无法以我想要的方式定义卷,因为以下定义:

Update

I've found that defining a volume the way I want could not be possible, since the following definition:

volumes:
  data-volume:
    type: bind
    source: ./code
    target: /var/www/html
    volume:
      nocopy: true

会在调用 docker-compose up 时生成此输出:

will produce this output when calling docker-compose up:

ERROR: The Compose file './docker-compose.yml' is invalid because:
volumes.data-volume value Additional properties are not allowed ('volume', 'source', 'type', 'target' were unexpected)

我想我仍然必须使用 volumes_from 然后。有人可以确认吗?

I guess I still have to use the volumes_from way then. Can anybody confirm that?

推荐答案

我可以确认您的观察结果:如果要挂载主机目录,则必须使用绑定安装语法。

I can confirm your observation: If you want to mount a host directory, you'll have to use the bind mount syntax.

这篇关于如何在docker compose中定义常规安装点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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