简体   繁体   English

在 docker-compose 中创建卷

[英]Creating volumes in docker-compose

I am trying to create a volume between two containers "abba" and "parser".我正在尝试在两个容器“abba”和“parser”之间创建一个卷。

However, when trying to execute docker-compose build I get this error: "Named volume "data-volume:parser/sample_files:rw" is used in service "parser" but no declaration was found in the volumes section."但是,当尝试执行docker-compose build我收到此错误:“命名卷“data-volume:parser/sample_files:rw”用于服务“parser”,但在卷部分中未找到任何声明。”

Here is my compose file:这是我的撰写文件:

version: '3'

services:
  abba:
    build:
      context: ./abba
      dockerfile: Dockerfile
    command: python abba/manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
      - data-volume:./abba/media
    ports:
      - "8000:8000"
    depends_on:
      - db
  parser:
    build:
      context: ./parser
      dockerfile: Dockerfile
    volumes:
      - data-volume:./parser/sample_files
  db:
    image: postgres
volumes:
  data_volume:

parser Dockerfile:解析器Dockerfile:

FROM python:3

ENV PYTHONUNBUFFERED 1

RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
EXPOSE 8000:8000

CMD ["python", "./parse.py"]

and abba Dockerfile和阿爸 Dockerfile

FROM python:3

ENV PYTHONUNBUFFERED 1

RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/

The thing I don't understand is why I get the error for the "parser" service, but not the "abba" service?我不明白的是为什么我收到“解析器”服务的错误,而不是“abba”服务的错误? It leads me to think that it works for the "abba" service, but not for the "parser" service.这让我认为它适用于“abba”服务,但不适用于“解析器”服务。 What am I not getting?我没有得到什么?

Thanks for the help in advance!我在这里先向您的帮助表示感谢!

You have a typo in the volume name in volumes: section.您在volumes:的卷名中有一个错字volumes:部分。 Change data_volume to data-volume .data_volume更改为data-volume

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

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