Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping PostgreSQL data in docker and OSX

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 ?

like image 316
ftshtw Avatar asked Apr 14 '16 05:04

ftshtw


People also ask

How to run PostgreSQL in Docker container?

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

How to persist database information of a docker container?

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.

How do I change the PostgreSQL username in Docker?

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.

How do I connect to a PostgreSQL database from another computer?

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.


1 Answers

OSX means boot2docker, and that Linux VM will:

  • only mount /Users (from your host)
  • only persists data from /var/lib/docker and /var/lib/boot2docker

So, /var/lib/postgresql is either:

  • not visible from the VM (not mounted)
  • not writable or persisted from within the VM

The command docker volume create should enable you to create a volume in the right path.
See:

  • "Managed data in container"
  • docker compose volumes
like image 62
VonC Avatar answered Nov 15 '22 04:11

VonC