'Why mysql docker data still exist after pulling and running new image and clearing cache?

I run mysql and a simple spring boot app for just getting a data to store in db with just simple controller and repository class.

I have added some data. Then I stopped all containers and deleted images and volumes

I run: docker system prune --volumes -a and when I run docker system df the output is:

TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          0         0         0B        0B
Containers      0         0         0B        0B
Local Volumes   0         0         0B        0B
Build Cache     0         0         0B        0B

As far as I understand there is nothing on pc except docker's itself.

But when I run my docker-compose.yml file with docker-compose up -d

It is downloading new image of mysql and building my app from it's docker file, but when I inspect the db, still I see old data in db. Here is my docker-compose.yml file:

version: '3.9'

services:
  mysql:
    platform: linux/amd64
    image: mysql:8
    container_name: mysqlcustomerdb
    restart: always
    ports:
      - '3306:3306'
    volumes:
      - ~/apps/mysql:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=1234
      - MYSQL_PASSWORD=1234
      - MYSQL_DATABASE=mysqlcustomerdb
      - DATABASE_HOST=mysqlcustomerdb
      - MYSQL_ROOT_HOST=%
      - lower_case_table_names=1
      - init-connect='GRANT CREATE USER ON . TO 'root'@'%';FLUSH PRIVILEGES;'

  dockerdeneme:
    container_name: dockerdeneme
    image: dockerdeneme
    build: ./
    restart: always
    deploy:
      restart_policy:
        condition: on-failure
        delay: 10s
        max_attempts: 3
        window: 120s
    ports:
      - '8080:8080'
    environment:
      - MYSQL_ROOT_PASSWORD=1234
      - MYSQL_PASSWORD=1234
      - MYSQL_USER=root
      - MYSQL_DATABASE=mysqlcustomerdb
    depends_on:
      - mysql
volumes:
  cache:
    driver: local

Why do the old data that I added to db is still coming even if I run docker system prune --volumes -a ? Am I missing some commands in docker compose file to refresh db or do I need to clear some folders from project etc ?



Solution 1:[1]

You're mounting a directory on the host into /var/lib/mysql. Since it's not a docker volume, you can't see it using docker commands.

Delete the contents of ~/apps/mysql on the host and your data should be gone.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hans Kilian