T
T
Tarakanishe2020-09-11 12:57:13
Django
Tarakanishe, 2020-09-11 12:57:13

What do volumes mean at the end of docker-compose.yml?

I'm trying to forward static from an application to nginx. There are 2 containers with an application and nginx in the article I found how to do it, but I can’t understand what the “static_volume” lines mean and where they are defined. If it were a folder, then the path would be - ./static_volume/:/home/app/web/staticfiles. I didn't find anything specific in the documentation.

version: '3.7'
services:
  web:
    build:
      context: ./app
      dockerfile: Dockerfile.prod
    command: gunicorn hello_django.wsgi:application --bind 0.0.0.0:8000
    volumes:
      - static_volume:/home/app/web/staticfiles
    expose:
      - 8000
    env_file:
      - ./.env.prod
  nginx:
    build: ./nginx
    volumes:
      - static_volume:/home/app/web/staticfiles
    ports:
      - 1337:80
    depends_on:
      - web
volumes:
  static_volume:


UPD: perhaps this is my stupidity and they thus indicated that I should enter my folder with static there, which I did. But the question remains, why do they write volumes at the end of the file if they are registered in services? Maybe some aliases, for example
volumes:
  static_volume:./app/static/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2020-09-11
@Tarakanishe

The volumes block defined at the first level of the yaml file (before or after servies, it doesn't matter) is intended to specify storage mount areas common to all services.
You have specified:

volumes:
  static_volume:

This means that a storage for data will be created locally on the disk. And specifically here:
/var/lib/docker/volumes/static_volume/_data
And it will be able to use those services to which you specify it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question