Removing named volumes when using Docker Compose

Adebayo A. Asamu 45 Reputation points
2023-01-15T11:53:52.6+00:00

Hello everyone.

I am try fairly new to docker and I am trying to set up an application using docker-compose (multi-container apps).

I installed the first version of the app and it was successful but I needed to add some configuration and changes some settings.

So I deleted the app service instance and tried to install again and it was successful.

The problem is that the app is still using the existing postgresql database. I have deleted the app service and started all over but the problem is still the same.

I tried to add docker-compose down --volumes

to the command script but can't find where to add.

Any help would be deeply appreciated.

Here is the sample docker-compose.yml

version: "3.8"
x-environment:
  &default-environment
  DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres
  SECRET_KEY: 39dfb4c28e4
  PORT: 8080
  EMAIL_URL: smtp://email:password@smtp_url:port # https://glitchtip.com/documentation/install#configuration
  GLITCHTIP_DOMAIN: https://glitchtip.example.com # Change this to your domain
  DEFAULT_FROM_EMAIL: contact@example.com # Change this to your email
  CELERY_WORKER_CONCURRENCY: 2
  GLITCHTIP_MAX_EVENT_LIFE_DAYS: 10
  ENABLE_ORGANIZATION_CREATION: "False"
  # ENABLE_USER_REGISTRATION: "False"
x-depends_on:
  &default-depends_on
  - postgres
  - redis

services:
  postgres:
    image: postgres:15
    environment:
      POSTGRES_HOST_AUTH_METHOD: "trust"
    restart: unless-stopped
    volumes:
      - pg-data:/var/lib/postgresql/data
  redis:
    image: redis
    restart: unless-stopped
  web:
    image: glitchtip/glitchtip
    depends_on: *default-depends_on
    ports:
      - "8080:8080"
    environment: *default-environment
    restart: unless-stopped
  worker:
    image: glitchtip/glitchtip
    command: ./bin/run-celery-with-beat.sh
    depends_on: *default-depends_on
    environment: *default-environment
    restart: unless-stopped
  migrate:
    image: glitchtip/glitchtip
    depends_on: *default-depends_on
    command: "./manage.py migrate"
    environment: *default-environment
volumes:
  pg-data:

The data in pg-data:/var/lib/postgresql/data remains in use even after deleting the app service.

Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
635 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
762 questions
{count} votes

Accepted answer
  1. Prrudram-MSFT 21,966 Reputation points
    2023-01-16T14:59:58.9066667+00:00

    Hello @Adebayo A. Asamu ,

    I see you have another thread posted with same issue. I am adding the solution here as well for the benefit of the community.
    The solution that worked for you is as follows:

    You can also delete the volume via Azure portal or Azure CLI.
    
    You can use a named volume instead of a host-mounted volume in your compose file to ensure that volume is deleted along with the deletion of the app service.
    
    
    Copy
    volumes:
      pg-data:
        name: pg-data
    This will create a named volume, which is managed by Docker and will be deleted when the app service is deleted.
    
    Please accept as answer and upvote if the above information has helped for the benefit of the community.
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful