docker-postgres-backup-local icon indicating copy to clipboard operation
docker-postgres-backup-local copied to clipboard

New volume created on each container startup

Open krzychuz opened this issue 2 years ago • 1 comments

I do use fairly standard docker-compose file:

postgresql_backup:
    container_name: my-db-backup
    image: prodrigestivill/postgres-backup-local
    restart: always
    volumes:
        - /opt/db_backups/:/backups
    links:
        - postgresql_database
    depends_on:
        - postgresql_database
    environment:
        - POSTGRES_HOST=postgresql_database
        - POSTGRES_DB=my-db
        - POSTGRES_USER=user
        - POSTGRES_PASSWORD=password
        - POSTGRES_EXTRA_OPTS=-Z6 --schema=public --blobs
        - SCHEDULE=@daily
        - BACKUP_KEEP_DAYS=7
        - BACKUP_KEEP_WEEKS=4
        - BACKUP_KEEP_MONTHS=6
        - HEALTHCHECK_PORT=8080
    networks:
      - my_network

While service itself works fine and backups are created correctly when inspecting the docker container I see that it has 2 mounts created:

{
    "Type": "bind",
    "Source": "/opt/db_backups",
    "Destination": "/backups",
    "Mode": "rw",
    "RW": true,
    "Propagation": "rprivate"
},
{
    "Type": "volume",
    "Name": "1befc40bfde09598482a395405354b1dc1ff02973f4b600f4ea212ba7d568b33",
    "Source": "/var/lib/docker/volumes/1befc40bfde09598482a395405354b1dc1ff02973f4b600f4ea212ba7d568b33/_data",
    "Destination": "/var/lib/postgresql/data",
    "Driver": "local",
    "Mode": "",
    "RW": true,
    "Propagation": ""
}

While the first one is totally expected, the other one seems to be re-created on each container startup and remains empty. This inevitably results in trashing docker/volumes with many not needed and empty volumes.

Is that result of my setup or can it be improved in container itself?

Thanks for letting me know!

krzychuz avatar Apr 03 '22 06:04 krzychuz

Okay, upon further investigation I realized that backup container actually specifies two anonymous volumes:

"Volumes": {
                "/backups": {},
                "/var/lib/postgresql/data": {}
            },

After adding this volume to docker compose as named volume it works as expected:

services:
  (...)
  postgresql_backup:
    (...)
    volumes:
        - /opt/db_backups/:/backups
        - backup-data:/var/lib/postgresql/data
     (...)
volumes:
  database-data:

Still I think the docker compose snipped in readme should be updated to avoid this by default 😉

krzychuz avatar Apr 03 '22 06:04 krzychuz