You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: postgres/content.md
+41
Original file line number
Diff line number
Diff line change
@@ -66,6 +66,47 @@ This optional environment variable can be used to define a different name for th
66
66
67
67
This optional environment variable can be used to send arguments to `postgres initdb`. The value is a space separated string of arguments as `postgres initdb` would expect them. This is useful for adding functionality like data page checksums: `-e POSTGRES_INITDB_ARGS="--data-checksums"`.
68
68
69
+
## Arbitrary `--user` Notes
70
+
71
+
As of [docker-library/postgres#253](https://github.com/docker-library/postgres/pull/253), this image supports running as a (mostly) arbitrary user via `--user` on `docker run`.
72
+
73
+
The main caveat to note is that `postgres` doesn't care what UID it runs as (as long as the owner of `/var/lib/postgresql/data` matches), but `initdb`*does* care (and needs the user to exist in `/etc/passwd`):
74
+
75
+
```console
76
+
$ docker run -it --rm --user www-data postgres
77
+
The files belonging to this database system will be owned by user "www-data".
78
+
...
79
+
80
+
$ docker run -it --rm --user 1000:1000 postgres
81
+
initdb: could not look up effective user ID 1000: user does not exist
82
+
```
83
+
84
+
The two easiest ways to get around this:
85
+
86
+
1. bind-mount `/etc/passwd` read-only from the host (if the UID you desire is a valid user on your host):
$ docker run -it --rm --user 1000:1000 -v pgdata:/var/lib/postgresql/data postgres
104
+
LOG: database system was shut down at 2017-01-20 00:03:23 UTC
105
+
LOG: MultiXact member wraparound protections are now enabled
106
+
LOG: autovacuum launcher started
107
+
LOG: database system is ready to accept connections
108
+
```
109
+
69
110
# How to extend this image
70
111
71
112
If you would like to do additional initialization in an image derived from this one, add one or more `*.sql` or `*.sh` scripts under `/docker-entrypoint-initdb.d` (creating the directory if necessary). After the entrypoint calls `initdb` to create the default `postgres` user and database, it will run any `*.sql` files and source any `*.sh` scripts found in that directory to do further initialization before starting the service.
0 commit comments