Removing named volumes when using docker-compose

Adebayo A. Asamu 45 Reputation points
2023-01-15T12:01:11.1633333+00:00

Hello everyone.

I am fairly new to docker and I am trying to deploy a multi-container app to azure app service using docker-compose.yml

I was able to successfully deploy the app.

I deleted the app service instance and tried deploying the app again and it was successful but the problem now is that the database from the first deployment was not deleted and the second deployment is now using the database.

Here is sample docker-compose.yml configuration

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:

I have removed and re-installed the app multiple times, but the volume is not deleted.

Any help will be appreciated.

Thank you.

Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
643 questions
Azure Container Apps
Azure Container Apps
An Azure service that provides a general-purpose, serverless container platform.
271 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
770 questions
0 comments No comments
{count} votes

Accepted answer
  1. Dimple Rane 906 Reputation points
    2023-01-15T12:06:50.38+00:00

    When you delete an Azure App Service instance, it will delete the resources associated with it, but it will not delete any persistent data associated with the app. In the case of your Docker Compose configuration, the volumes section specifies that a volume named pg-data should be used to store data for the postgres container. This volume is not deleted when you delete the App Service instance, so the data stored in it will persist across deployments.

    To ensure that the volume is deleted when you delete the App Service instance, you will need to remove the volume manually. You can do this by running the following command:

    docker volume rm pg-data
    

    You can also delete the volume via Azure portal or Azure CLI.

    Alternatively, 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.

    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.

    3 people found this answer helpful.

0 additional answers

Sort by: Most helpful