简体   繁体   中英

Creating volumes in docker-compose

I am trying to create a volume between two containers "abba" and "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."

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:

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

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? It leads me to think that it works for the "abba" service, but not for the "parser" service. What am I not getting?

Thanks for the help in advance!

You have a typo in the volume name in volumes: section. Change data_volume to data-volume .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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