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:
docker compose down --volume --remove-orphans
– when I recreate new container, previously persisted data still exists- There is no folder called
./db-data
in my Mac working directory. - I tried searching
var/lib/docker
in my Mac. But that directory does not exists. - Docker for Mac app doesn’t list any volumes
- There is no
db-data
in the remote host where the database is deployed
2
Answers
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 prefixUsers/<user-name>
but this path was actually found in the root of the remote machine.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