I have an OSX host with a postgreSQL database (actually experimenting with it for Redmine). All I want is to be able to keep data after I destroy a container so I'll be safe and I can re-deploy my repository fast.
If I try to add a local Volume in Kitematic, the container fails to start with error:
initdb: could not create directory "/var/lib/postgresql/data/pg_xlog/archive_status": Permission denied
initdb: removing contents of data directory "/var/lib/postgresql/data"
creating subdirectories ...
I've tried to chmod 777 -R the local folder but same result. Does anyone have any solution for this or anything else to suggest on saving/keeping data from postgreSQL and docker ?
How to Run PostgreSQL Using Docker 1 Setup. First, we need to install Docker. ... 2 Inspection. We can check if the container is running or not using the docker ps command on the host machine. ... 3 Connect to psql. What is psql? ... 4 Load data from a file. Now we can load the dump file into our test_db database. ... 5 Wrap Up
But as you can see that the data/ directory persists. Next, run docker-compose up again to start the database container. If you shell into the container and login into the PostgreSQL console. You can see that your table data isn’t lost. And that’s how you persist database information of a docker container.
The username defaults to postgres but can be changed by setting the POSTGRES_USER environment variable. The -v flag is used to mount a Docker volume to the PostgreSQL container’s data directory. A named volume called postgres is referenced; Docker will either create it or reattach the volume if it already exists.
RUN /etc/init.d/postgresql start &&\ psql --command "CREATE USER docker WITH SUPERUSER PASSWORD 'docker';" &&\ createdb -O docker docker # Adjust PostgreSQL configuration so that remote connections to the # database are possible.
OSX means boot2docker, and that Linux VM will:
/var/lib/docker
and /var/lib/boot2docker
So, /var/lib/postgresql
is either:
The command docker volume create
should enable you to create a volume in the right path.
See:
docker compose
volumesIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With