简体   繁体   中英

Named volume not being created in docker

I'm trying to create a django/nginx/gunicorn/postgres docker-compose configuration.

Every time I call docker-compose down, I noticed that my postgres db was getting wiped. I did a little digging, and when I call docker-compose up, my named volume is not being created like i've seen in other tutorials.

What am I doing wrong?

Here is my yml file (if it helps, I'm using macOS to run my project)

version: "3"
volumes:
  postgres:
    driver: local

services:
  database:
    image: "postgres:latest" # use latest postgres 
    container_name: database
    environment:
      - POSTGRES_USER=REDACTED
      - POSTGRES_PASSWORD=REDACTED
      - POSTGRES_DB=REDACTED
    volumes:
      - postgres:/postgres
    ports:
    - 5432:5432


  nginx:
    image: nginx:latest
    container_name: nginx
    ports:
      - "8000:8000"
    volumes:
      - ./src:/src
      - ./config/nginx:/etc/nginx/conf.d
      - ./src/static:/static 
    depends_on:
      - web

  migrate:
    build: .
    container_name: migrate
    depends_on: 
    - database  
    command: bash -c "python manage.py makemigrations && python manage.py migrate"
    volumes:
      - ./src:/src
  web:
    build: .
    container_name: django
    command: gunicorn Project.wsgi:application --bind 0.0.0.0:8000
    depends_on:
      - migrate
      - database

    volumes:
      - ./src:/src
      - ./src/static:/static 
    expose:
      - "8000"

You need to mount the data directory at /var/lib/postgresql/data

volumes:
  - postgres:/var/lib/postgresql/data

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