Docker Volumes on Mac with Postgres

Viewed 1983

I'm attempting to run the following command on Mac OSX:

docker run --rm --name kong-database \
    --network=kong-net \
    -v /Volumes/docker/postgres:/var/lib/postgresql/data \
    -p 5432:5432 \
    -e "POSTGRES_USER=kong" \
    -e "POSTGRES_DB=kong" \
    postgres:9.6

With the intention that it will launch postgres in in a docker container, and persist the database data on my local file system in /Volumes/docker/postgres. However, I get the following error, and the container fails to run:

chown: changing ownership of '/var/lib/postgresql/data': Operation not permitted

Any idea what I can do to get this going?

2 Answers

Turns out that /Volumes was owned by root. When I switched this to something like /Users/JoshuaErney/Volumes, this ran successfully. Here's an example:

docker run --rm --name kong-database \
    --network=kong-net \
    -v /Users/JoshuaErney/Volumes/docker/postgres:/var/lib/postgresql/data \
    -p 5432:5432 \
    -e "POSTGRES_USER=kong" \
    -e "POSTGRES_DB=kong" \
    postgres:9.6

Answer by jerney is correct, here is what it looks like with docker-compose.yaml:

services:
  test-postgres-compose :
    ...
    volumes :
      - pgdata:/var/lib/postgresql/data
...
volumes :
  pgdata :

Docker compose volumes info

Related