skip to Main Content

I have a docker-compose.yml which I am using to deploy to a remote host from my local (Mac) machine using docker context. The compose config is as follows:

database:
    image: postgres:14.2
    restart: on-failure

    volumes:
      - ./db-data:/var/lib/postgresql/data

    environment:
      POSTGRES_DB: db
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres

In order to persist data, I have defined a volume ./db-data:/var/lib/postgresql/data. This db-data folder does not exist in my local machine. I want delete this mount completely because I don’t want any of the previously persisted data. I know I can define a new volume directory but I would like to use the same directory name (db-data). I have tried the following:

  1. docker compose down --volume --remove-orphans – when I recreate new container, previously persisted data still exists
  2. There is no folder called ./db-data in my Mac working directory.
  3. I tried searching var/lib/docker in my Mac. But that directory does not exists.
  4. Docker for Mac app doesn’t list any volumes
  5. There is no db-data in the remote host where the database is deployed

2

Answers


  1. Chosen as BEST ANSWER

    Running docker inspect <container-id> listed the mount directory for the container. The mount directory resembled absolute path of my local computer. For example it was like /Users/<user-name>/dir/db-data. When I saw this I assumed this had to be in the local computer due to the prefix Users/<user-name> but this path was actually found in the root of the remote machine.


  2. Thats because the directory for docker volumes is in the docker vm for MACOS.
    Where is /var/lib/docker on Mac/OS X

    You would have to follow this to see the volume

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search