Git Product home page Git Product logo

postgres's Introduction

This is the Git repo of the Docker "Official Image" for postgres (not to be confused with any official postgres image provided by postgres upstream). See the Docker Hub page for the full readme on how to use this Docker image and for information regarding contributing and issues.

The full image description on Docker Hub is generated/maintained over in the docker-library/docs repository, specifically in the postgres directory.

See a change merged here that doesn't show up on Docker Hub yet?

For more information about the full official images change lifecycle, see the "An image's source changed in Git, now what?" FAQ entry.

For outstanding postgres image PRs, check PRs with the "library/postgres" label on the official-images repository. For the current "source of truth" for postgres, see the library/postgres file in the official-images repository.


  • build status badge
  • build status badge
Build Status Badges (per-arch)
amd64 build status badge arm32v5 build status badge arm32v6 build status badge arm32v7 build status badge
arm64v8 build status badge i386 build status badge mips64le build status badge ppc64le build status badge
s390x build status badge put-shared build status badge

postgres's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

postgres's Issues

pgadmin connection error

On connection by pgadmin to new database it get error: Error connctiong to the server: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request

Add a README file with content from the Docker Hub page

The discussion in the comments, especially those with examples, on the Docker Hub Registry page for this repository was super helpful to me. It would be great if a README could be added that contained some of the FAQs and/or comments explaining some of the ways one can customize this image.

I would gladly contribute if someone smarter than me wanted to give it a first pass. ;)

No permissions to delete /var/lib/postgresql/data

This is how I run Postgres container:

docker run -d \
           -v /etc/fxz/postgres:/var/lib/postgresql/data \
           -e LC_ALL=C.UTF-8 \
           -p 5432:5432 \
           --name=postgres \
           postgres

I can see created directory:

$ ls -l /etc/fxz/
drwx------ 15  999 root 4096 Nov 12 10:59 postgres

But the problem is that I have no permissions to delete it:

$ rm -rf /etc/fxz/postgres/
rm: cannot remove '/etc/fxz/postgres/': Permission denied

If I do it as root, it works.

Are there any way to delete it as non-root user? I am in docker group already.

docker-entrypoint.sh permission denied

I have a problem launching the container :
2014/09/16 08:56:36 Error response from daemon: Cannot start container 19c947b7844207f0e41e1ed6a6ec130cb0659667a53cf29ad98cde68b0cd5c6e: exec: "/docker-entrypoint.sh": permission denied

Here some output :
root@db:~# ls
docker-entrypoint.sh Dockerfile start.sh

to build the image :
docker build -t postgres .

to run the image :
docker run -t -i -p 5432:5432 --name postgresql -d postgres /bin/bash

Unable to run postgres container on Ubuntu 15.04

I tried to run postgres container on Ubuntu 14.04 and it worked fine, but when i tried to run on Ubuntu 15.04 server i got error:

/docker-entrypoint.sh: line 94: kill: (59) - No such process
PostgreSQL init process failed

Using postgresql with external volume from Mac

I am trying to mount it directly from the Mac file system.

docker run  -v $HOME/postgres_data:/var/lib/postgresql kartoza/postgi

This results in a bunch of errors about user permissions:

initdb: could not create directory "/var/lib/postgresql/9.3/main/global": Permission denied
2015-01-07 16:33:52 UTC FATAL:  data directory "/var/lib/postgresql/9.3/main" has wrong ownership
2015-01-07 16:33:52 UTC HINT:  The server must be started by the user that owns the data directory.

Can a directory shared from Mac file system ever have the read/write permissions that postgres apparently needs?

Add autopostgresqlbackup package

Hi

What are your thoughts about including the autopostgresqlbackup package into the image? I just tried to run it (docker exec -ti db autopostgresqlbackup) and it works nicely.
Nothing should change by including it as autopostgresqlbackup is executed by cron which is not running in the postgres container.

root@48e4deef5553:/# dpkg -L autopostgresqlbackup
/.
/etc
/etc/default
/etc/default/autopostgresqlbackup
/etc/cron.daily
/etc/cron.daily/autopostgresqlbackup
/usr
/usr/sbin
/usr/sbin/autopostgresqlbackup
/usr/share
/usr/share/doc
/usr/share/doc/autopostgresqlbackup
/usr/share/doc/autopostgresqlbackup/copyright
/usr/share/doc/autopostgresqlbackup/changelog.Debian.gz
/usr/share/man
/usr/share/man/man8
/usr/share/man/man8/autopostgresqlbackup.8.gz
/var
/var/lib
/var/lib/autopostgresqlbackup

Or are there other best practices for creating SQL dumps as backup?

Can't connect from other applications by default

Seeing the following in docker-entrypoint.sh:

{ echo; echo "host all \"$POSTGRES_USER\" 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf

Today I tried to launch a Redmine container I'd built with this image in mind, and have working on another host, and it failed due to a missing pg_hba.conf line. When I compared the working line with the newly-generated one, I discovered "all" was replaced with $POSTGRES_USER.

Why is this? I guess I can spin up a new database per app, but that seems a bit wasteful. Also, if I understand correctly, I'm now expected to connect my app authenticating against $POSTGRES_USER, which is a superuser. So, unless I'm missing something, you've switched the default mode of operation from "everyone can connect, with authorization handled on the user level" to "only $POSTGRES_USER can connect by default, and $POSTGRES_USER is superuser." That strikes me as absolutely backwards, in the sense that I should be handing out credentials piecemeal rather than connecting to the superuser by default.

I know I can change this with my own scripts, but unless I'm missing something, this default seems absolutely broken.

Cannot link to database from other container

Since last updates, see what happens:

$ docker run -it --rm --name db postgres:9.2
[...]
LOG:  database system is ready to accept connections
[...]

Now open another terminal and do:

$ docker run -it --rm --link db:db postgres:9.2 bash -c 'psql -h $DB_PORT_5432_TCP_ADDR -p $DB_PORT_5432_TCP_PORT -U postgres'
psql: could not connect to server: No route to host
    Is the server running on host "172.17.0.162" and accepting
    TCP/IP connections on port 5432?

Of course it is!:

docker exec -it db bash -c 'apt-get -qq update && apt-get -qq install net-tools && netstat --listen'
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 *:postgresql            *:*                     LISTEN     
tcp6       0      0 [::]:postgresql         [::]:*                  LISTEN     
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     966410   /var/run/postgresql/.s.PGSQL.5432

I'm not sure what the bug is, but seems like the Postgres port is not available to the client, since nmap does not report anything too...

$ docker run -it --rm --link db:db uzyexe/nmap db

Starting Nmap 6.47 ( http://nmap.org ) at 2015-07-16 11:56 UTC
Nmap scan report for db (172.17.0.162)
Host is up (0.000067s latency).
All 1000 scanned ports on db (172.17.0.162) are filtered
MAC Address: 02:42:AC:11:00:A2 (Unknown)

Nmap done: 1 IP address (1 host up) scanned in 11.99 seconds

It's pretty frustrating 😞

:latest in postgres from Docker Hub fails due to permissions issue

When I try:

docker run -it postgres

The process dies with the following output:

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "C".
The default database encoding has accordingly been set to "SQL_ASCII".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
creating configuration files ... ok
creating template1 database in /var/lib/postgresql/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    postgres -D /var/lib/postgresql/data
or
    pg_ctl -D /var/lib/postgresql/data -l logfile start

FATAL:  could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied

I haven't played with this image enough to know it well, so I can't speculate too much, but we tell people doing docker run --name db -d postgres (which gives same error) is fine, so it shouldn't just die like this.

How to use as a base image?

I'm trying to use this as a base image, and set different databases and users in my Dockerfile, but am having trouble accessing the files in mounted as VOLUME. Here's what I have:

Dockerfile

FROM postgres
VOLUME /var/lib/postgresql/data
ADD setup_db.sh /code/
RUN /code/setup_db.sh

setup_db.sh

#!/bin/bash

gosu postgres postgres
createdb mydb
# createuser myrole
# postgres stop

But when I try to build my image I get:

$ docker build --tag="pgdock" .
Sending build context to Docker daemon 17.92 kB
Sending build context to Docker daemon
Step 0 : FROM postgres
 ---> 2f007d4a5aa5
Step 1 : VOLUME /var/lib/postgresql/data
 ---> Using cache
 ---> ccfab417f4c2
Step 2 : RUN ls -l /var/lib/postgresql/data/
 ---> Using cache
 ---> c1194d442777
Step 3 : ADD setup_db.sh /code/
 ---> Using cache
 ---> d50b814fb7f9
Step 4 : RUN /code/setup_db.sh
 ---> Running in 233e6b4fe77b
postgres cannot access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory
createdb: could not connect to database template1: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
2014/08/24 15:39:35 The command [/bin/sh -c /code/setup_db.sh] returned a non-zero code: 1

Any advice?

PostgreSQL image is open to the world

Hi,

is there any good reason I am not aware of why this postgres installation should be open to the world by this line inside docker-entrypoint.sh:

host all all 0.0.0.0/0 trust

Isn't it a better way to allow the postgres user to authenticate via password and set a default password once at startup. This way the password can be changed after starting the container via psql.

Best regards

Ingo

Create /docker-entrypoint-initdb.d directory by default

Currently one needs to put at last two lines to install custom initialization script:

RUN mkdir /docker-entrypoint-initdb.d
COPY ./some-script.sh /docker-entrypoint-initdb.d/some-script.sh

There would be no harm to have empty /docker-entrypoint-initdb.d directory for user scripts but it would make extending images easier by reducing previous example to:

COPY ./some-script.sh /docker-entrypoint-initdb.d/some-script.sh

As a side effect, this change would also simplify docker-entrypoint.sh (one test less) but what is most important here, users will gain ability to just COPY their scripts without need to manage destination directory (which is already specified in docker-entrypoint.sh.)

FATAL: could not create lock file “/var/run/postgresql/.s.PGSQL.5432.lock”: Permission denied

I was running into that issue using this image without any custom Dockerfile.

$ boot2docker version
Client version: v1.1.2
Git commit: 429947b

$ docker version
Client version: 1.1.2
Client API version: 1.13
Go version (client): go1.2.1
Git commit (client): d84a070
Server version: 1.1.2
Server API version: 1.13
Go version (server): go1.2.1
Git commit (server): d84a070

I've managed to fix the issue with the following:

sed -ri "s/^#unix_socket_directories = .*$/unix_socket_directories = '\/tmp'/" "$PGDATA"/postgresql.conf

Though I had to use a custom docker-entrypoint.sh because at build time there is no postgresql.conf file.

Default encoding is SQL_ASCII

$ docker run -d --name db postgres
fb08c3d5d9081350f8bc4f9de40d7a31f014c3e1c83382bcc9868eff84a42116

$ docker run --link db:db -i -t postgres psql -h db -U postgres
psql (9.3.5)
Type "help" for help.

postgres=# \l
                             List of databases
   Name    |  Owner   | Encoding  | Collate | Ctype |   Access privileges
-----------+----------+-----------+---------+-------+-----------------------
 postgres  | postgres | SQL_ASCII | C       | C     |
 template0 | postgres | SQL_ASCII | C       | C     | =c/postgres          +
           |          |           |         |       | postgres=CTc/postgres
 template1 | postgres | SQL_ASCII | C       | C     | =c/postgres          +
           |          |           |         |       | postgres=CTc/postgres
(3 rows)

Personally, I'd rather it were UTF-8. Thoughts?

Initilizations scripts in docker-entrypoint-initdb.d cannot be executed to existing lock file

My initialisation scripts from /docker-entrypoint-initdb.d/ ceased to work with latest update

db_1 | /docker-entrypoint.sh: running /docker-entrypoint-initdb.d/setup-database.sh
db_1 | FATAL: lock file "postmaster.pid" already exists
db_1 | HINT: Is another postmaster (PID 54) running in data directory "/var/lib/postgresql/data"?

This fetaure (any my scripts) were working fine for previous few months - only latest update introduced some breaking changes

How to add additional users and databases?

I can add additionally users and database with psql as soon as the postgres server is started. With this docker image the binary is started via docker-entrypoint.sh How can I automate this within my own Dockerfile?

I assume I would need to write a script that I call within my Dockerfile as an entrypoint. This script would need to start the database server, then execute the commands with psqland afterwards stop the db server again and let the original docker-entrypoint.sh entrypoint taken place. However I'm not sure: how can I start and stop a postgres server manually within my custom script with this postgres docker image?

thanks
m

could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied

dmaze@monad:~$ docker images postgres
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
postgres            9.3                 7b9abcbfddf1        7 hours ago         482.5 MB
postgres            latest              7b9abcbfddf1        7 hours ago         482.5 MB
dmaze@monad:~$ docker run postgres
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
[...]
Success. You can now start the database server using:

    postgres -D /var/lib/postgresql/data
or
    pg_ctl -D /var/lib/postgresql/data -l logfile start

FATAL:  could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied

If I log into the container directly, I see the directory /var/run/postgresql/ is mode 2775 owned by root:root, so the postgres:postgres user:group can't actually create a pid file there.

persistent storage?

How to make sure it runs with persistent storage it would help if there would be something about this in the readme.

Pre-migrated images

I wanted to do some pre-migrations as part of the build so that the container can start quicker in tests.
AFAIS this is not currently possible, as /var/lib/postgresql/data is specified as a VOLUME and during docker build all changes to the VOLUMEs seem to be no-ops. In contrast, first creating a directory and later mounting that same directory as VOLUME will copy all files over.

See this minimal example, first with the VOLUME being mounted at the end

Step 0 : FROM debian:wheezy

Step 1 : RUN mkdir /myvol

Step 2 : RUN ls -lah /myvol
total 8.0K
drwxr-xr-x  2 root root 4.0K Apr 22 23:27 .
drwxr-xr-x 29 root root 4.0K Apr 22 23:27 ..

Step 3 : RUN echo "hello world" > /myvol/greeting

Step 4 : RUN ls -lah /myvol
total 12K
drwxr-xr-x  2 root root 4.0K Apr 22 23:27 .
drwxr-xr-x 30 root root 4.0K Apr 22 23:27 ..
-rw-r--r--  1 root root   12 Apr 22 23:27 greeting

Step 5 : VOLUME /myvol

Step 6 : RUN ls -lah /myvol
total 12K
drwxr-xr-x  2 root root 4.0K Apr 22 23:27 .
drwxr-xr-x 30 root root 4.0K Apr 22 23:27 ..
-rw-r--r--  1 root root   12 Apr 22 23:27 greeting

Now, when you mount the VOLUME already at the beginning:

Step 0 : FROM debian:wheezy

Step 1 : VOLUME /myvol

Step 2 : RUN ls -lah /myvol
total 8.0K
drwxr-xr-x  2 root root 4.0K Apr 22 23:29 .
drwxr-xr-x 29 root root 4.0K Apr 22 23:29 ..

Step 3 : RUN echo "hello world" > /myvol/greeting

Step 4 : RUN ls -lah /myvol
total 8.0K
drwxr-xr-x  2 root root 4.0K Apr 22 23:29 .
drwxr-xr-x 29 root root 4.0K Apr 22 23:29 ..

Do you see any way around this or another possibility to perform operations on the DB that make it into the image (vs. being executed only on docker run)?

Security issue: Newly created roles with password are allowed to connect w/o password prompt

How to reproduce:

  • run a container to listen on some port, create new user and database:

    docker run -p 5432:5432 -d --name postgres postgres:9.3.5
    psql -h localhost -p 5432 -U postgres
    =# create database test; create user test with password 'test'; GRANT ALL privileges ON DATABASE test TO test; \q

After that I would expect that test user can login using his/her password.

psql -h localhost -p 5432 -U test

But password is not required(!!!)
This is really weird and unexpected behavior.

Extending DB initialization in docker-entrypoint.sh

I'm working on creating a PostGIS container based on this one and ended up replacing the docker-entrypoint.sh with my own modified version in order to create a template_postgis database (cf. https://github.com/md5/docker-postgis/blob/master/docker-entrypoint.sh#L10-17).

I'd like to propose that docker-entrypoint.sh somehow be extended to allow derived images to do additional work when a new database is being initialized. I can provide a PR with a patch, assuming there's agreement that this is a desirable change. I'd probably default to using a /docker-entrypoint.d/ directory or something of that sort.

How to connect from host VM (not a linked container)?

I'm able to connect from the host using psql using:

docker run -it --link some-postgres:postgres --rm postgres sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres'

Is it possible to connect directly from the host without creating a linked container? I.e. why can't I run psql -h localhost -p 5432 -U postgres directly?

Default pg_hba is extremely insecure

It might be more reasonable to replace the following line in pg_hba
echo 'host all all 0.0.0.0/0 trust';
with
echo 'host all all 0.0.0.0/0 md5';

Because the current configuration simply enables anyone in the world to connect to the database with no authentication whatsoever, which is really a very serious security problem because it is very likely that someone might leave the default setting of the image!

Quoting PostgreSQL documentation

trust
Allow the connection unconditionally. This method allows anyone that can connect to the PostgreSQL database server to login as any PostgreSQL user they wish, without the need for a password or any other authentication

Upgrading to jessie?

If I want to use this image with another image which is based on jessie, would it bloat the whole system size? If true, shall I upgrade this image to jessie?

WARNING: enabling "trust" authentication for local connections

It looks like postgres docker image is still "open" despite latest introduction of password and user name.
Default configuration file pg_hba.conf contains following lines:

# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust

When password is given withe -e option to docker run command

host all "postgres" 0.0.0.0/0 md5

line is added to pg_hba.conf. This restricts access for postgres user but for all other users it's still unconditionally trust.

cluster locale

How to set the locale of database cluster? the default is "en_US.utf8", but I want to set it before start the image.

Losing schema updates with --volumes-from

I am launching postgres container with a data-only container. Say we'll name them "postgres" and "postgres-data". "postgres" is run with --volumes-from "postgres-data" for data persistence.

The weird issue is that sometimes when I add a column to a table and stop, remove and rerun "postgres" the newly created column disappears. What is even more weird is that the rows on the other hand persist. If I add a row and a column, and the stop, remove and rerun with --volumes-from again, the column will disappear, but the row will be there!

This is an obviously critical issue for us preventing production usage.

Does PostgreSQL stores schema updates separately from data updates? Where the schema updates are stored? Are they included in a VOLUME?

ERROR: function uuid_generate_v4() does not exist

I ran this:

begin;
create extension "uuid-ossp";
create table products (product_id  uuid primary key default uuid_generate_v4());
create table orders   (order_id    uuid primary key default uuid_generate_v4(),
                      product_id   uuid references products not null);

But I get ERROR: function uuid_generate_v4() does not exist

Are the contrib modules and extensions installed with this image?

Error while using kitematic to create a postgres container

Kitematic sample containers work fine, no issue, including hello-world-nginx, ghost, etc.

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
initdb: could not create directory "/var/lib/postgresql/data/global": Permission denied
initdb: removing contents of data directory "/var/lib/postgresql/data"

Thanks!

"/var/lib/postgresql/data/global" Under boot2docker on Yosemite

I am trying to run this box on a Mac OS 10.10 system with boot2docker and Docker 1.3 running. Here is the output that I get:

$  fig run db
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... initdb: could not create directory "/var/lib/postgresql/data/global": Permission denied
initdb: removing contents of data directory "/var/lib/postgresql/data"

I am having it use an external volume so that the database can persist between each run. This is done through fig:

db:
  image: postgres:9.3
  ports:
    - "5432"
  volumes:
    - "../pg_data:/var/lib/postgresql/data"

I suspect that this is related to #26 . I tried clearing ~/.boot2docker and removing the VM without success.

Let me know if there is something else you need.

Upgrading between major versions?

There doesn't seem to be a good way to upgrade between major versions of postgres. When sharing the volume with a new container with a newer version of postgres it won't run as the data directory hasn't been upgraded. pg_upgrade on the other hand requires (?) old installation binary files, so upgrading the data files from new server container is also difficult.

It would be nice if there was some suggested way of doing this in the readme. Maybe even some meta container which does the upgrading from version to version?

postgres /docker-entrypoint.sh not running scripts in /docker-entrypoint-initdb.d/

I'm having trouble writing a script to /docker-entrypoint-initdb.d/ and having Docker run it from /docker-entrypoint.sh.

  • It looks like /docker-entrypoint.sh is supposed to source any scripts it finds in /docker-entrypoint-initdb.d/. I verified I'm running this version of the script by cating the script and verifying this is the expected behavior.
  • I followed the instructions in "justfalter"'s comment here: https://registry.hub.docker.com/_/postgres/ to add a fix-acl.sh file and put it in the correct folder. I double checked the folder name was correct.
  • I also mirrored the commands in the /docker-entrypoint.sh script to check that the script could be sourced and would produce the desired behavior.
  • When I do "docker run", it's clear that Postgres starts but the specified line was not added to pg_hba.conf. I double checked this by verifying the mtime of pg_hba.conf - it wasn't touched or overwritten after my script ran. I also tried having my script touch various files to just verify that it ran, with no success.

I'm at a loss for how to continue debugging this; I placed a file in the place that it's supposed to go, verified that the script runner that starts postgres should run it, and verified that the script does what I want, and I don't see any output (a changed pg_hba.conf, or even a simple file).

I'm running the newest version of everything; starting Docker inside of a Ubuntu Virtualbox being provisioned from Vagrant. I share one folder from the Docker container to the host VM - the data folder containing pg_hba.conf.

Would appreciate your help!
Kevin

Image reports that it's "up" before it's actually listening

If I have a docker compose file, listing a server that must talk to postgres, and a postgres instance, linked together, docker starts the service that depends on postgres before postgres has finished starting.

Log excerpt attached. Current workaround is to include a "sleep 5 &&" prefixed to the start command for the application server, but this is very much non-ideal.

db_1 | PostgreSQL stand-alone backend 9.3.6
db_1 | backend> backend>
db_1 | PostgreSQL stand-alone backend 9.3.6
db_1 | backend> backend>
db_1 | PostgreSQL stand-alone backend 9.3.6
db_1 | backend> backend>
db_1 | PostgreSQL stand-alone backend 9.3.6
db_1 | backend> backend>
db_1 | PostgreSQL stand-alone backend 9.3.6
app_1 | 2015-04-22 23:46:12,445 INFO success: flask_server entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
app_1 | 2015-04-22 23:46:12,445 INFO success: cache_syncd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
db_1 | backend> backend>
db_1 | PostgreSQL stand-alone backend 9.3.6
db_1 | backend> backend>
db_1 | PostgreSQL stand-alone backend 9.3.6
db_1 | backend> backend>
db_1 | PostgreSQL stand-alone backend 9.3.6
db_1 | backend> backend>
db_1 | PostgreSQL stand-alone backend 9.3.6
db_1 | backend> backend> LOG: database system was shut down at 2015-04-22 23:46:13 UTC
db_1 | LOG: database system is ready to accept connections
db_1 | LOG: autovacuum launcher started

How to set up replication?

I have been trying to set up replication on the version 9.3 of the image, and having quite a lot of difficulty. I'm curious if this is possible... The README states the "recent versions" are able to support replication, but is 9.3 one of those?

"/var/lib/postgresql/data/pg_xlog/archive_status": Permission denied

Under docker 1.3.0 and boot2docker 1.3.0 postgres:9.3 quits with the following error:

docker run --rm --name postgres --volume /Users/remmelt/postgres:/var/lib/postgresql/data postgres

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... initdb: could not create directory "/var/lib/postgresql/data/pg_xlog/archive_status": Permission denied
Boot2Docker-cli version: v1.3.0
Git commit: deafc19
Docker version 1.3.0, build c78088f

I think this is due to the new boot2docker volume support in 1.3.0. I can see the directory mounted in the boot2docker volume, they are owned by docker(1000)/staff.

$ id docker
uid=1000(docker) gid=50(staff) groups=50(staff),100(docker)

My local OSX user has id 501.

$ id remmelt
uid=501(remmelt) gid=20(staff)

Inside the postgres container, the postgres user has uid 999, and the directory is owned by an unknown user with uid 1000, probably inherited from boot2docker.
I cannot change the ownership of the mounted volume from inside the container, not even when using root.

I thought that a quick fix would be to give the postgres user uid 1000. This works in that the postgres user is now owner of the /var/lib/postgres/data directory and can create files, but it throws the following immediately after:

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
creating configuration files ... ok
creating template1 database in /var/lib/postgresql/data/base/1 ... LOG:  could not link file "pg_xlog/xlogtemp.22" to "pg_xlog/000000010000000000000001" (initialization of log file): Operation not permitted
FATAL:  could not open file "pg_xlog/000000010000000000000001": No such file or directory
child process exited with exit code 1
initdb: removing contents of data directory "/var/lib/postgresql/data"

I see a comment on line 4 of the 9.3 Dockerfile that reads "# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added" so I don't know if you're doing any magic with the uid.

Change ownership of /var/run/postgresql on startup

Currently, the init script changes the ownership of /var/lib/postgresql/data to make sure the postgres user can write to it's data directory.

However, when starting a postgres container, I use a data volume that shares both /var/lib/postgresql/data for storing the data, and /var/run/postgresql for storing the postgres sockets - so I don't have to use networking. The containers that need access to postgres are started with mounting my data volume and accessing (what they think is) the local unix socket. This way can easily give another container access to my postgres database without network discovery or network overhead, eliminating a lot of potential problems and improving security.

The problem however is that when you create a volume like this, I have to launch a temporary container to fix the permissions of /var/run/postgresql before launching my postgres server.

Cannot mount host directory as /var/lib/postgresql/data volume

This is on OSX using docker-machine. Doesn't happen on Ubuntu, and it's the first time I've seen this behaviour in general.

The simplest invocation is failing:

$ docker run \
→     --volume "$PWD/persistent":/var/lib/postgresql/data \
→     postgres:latest
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.


The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... initdb: could not create directory "/var/lib/postgresql/data/global": Permission denied
initdb: removing contents of data directory "/var/lib/postgresql/data"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.