postgre won't work using docker-compose

5,977 views
Skip to first unread message

Rj He

unread,
Dec 6, 2019, 12:13:06 PM12/6/19
to xnat_discussion
Hi, All,


I got problem as, any idea to fix it:

PS C:\xnatmaster> docker-compose up -d
Creating network "xnatmaster_default" with the default driver
Creating xnatmaster_xnat-db_1 ... done
Creating xnatmaster_xnat-web_1 ... done
Creating xnatmaster_xnat-nginx_1 ... done
PS C:\xnatmaster> docker container ls -a
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS                      PORTS                                            NAMES
2a44f6e9598d        xnatmaster_xnat-nginx   "nginx -g 'daemon of…"   14 seconds ago      Up 12 seconds               0.0.0.0:80->80/tcp                               xnatmaster_xnat-nginx_1
f439421c0d88        xnatmaster_xnat-web     "wait-for-postgres.s…"   17 seconds ago      Up 14 seconds               0.0.0.0:8000->8000/tcp, 0.0.0.0:8081->8080/tcp   xnatmaster_xnat-web_1
61ea8d8d138b        xnatmaster_xnat-db      "docker-entrypoint.s…"   20 seconds ago      Exited (1) 17 seconds ago                                                    xnatmaster_xnat-db_1
PS C:\xnatmaster> docker container start 61ea8d8d138b
61ea8d8d138b
PS C:\xnatmaster> docker container ls -a
CONTAINER ID        IMAGE                   COMMAND                  CREATED              STATUS                     PORTS                                            NAMES
2a44f6e9598d        xnatmaster_xnat-nginx   "nginx -g 'daemon of…"   56 seconds ago       Up 54 seconds              0.0.0.0:80->80/tcp                               xnatmaster_xnat-nginx_1
f439421c0d88        xnatmaster_xnat-web     "wait-for-postgres.s…"   59 seconds ago       Up 56 seconds              0.0.0.0:8000->8000/tcp, 0.0.0.0:8081->8080/tcp   xnatmaster_xnat-web_1
61ea8d8d138b        xnatmaster_xnat-db      "docker-entrypoint.s…"   About a minute ago   Exited (1) 7 seconds ago                                                    xnatmaster_xnat-db_1
PS C:\xnatmaster> docker container start 61ea8d8d138b
61ea8d8d138b
PS C:\xnatmaster> docker container ls -a
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS                     PORTS                                            NAMES
2a44f6e9598d        xnatmaster_xnat-nginx   "nginx -g 'daemon of…"   3 minutes ago       Up 3 minutes               0.0.0.0:80->80/tcp                               xnatmaster_xnat-nginx_1
f439421c0d88        xnatmaster_xnat-web     "wait-for-postgres.s…"   3 minutes ago       Up 3 minutes               0.0.0.0:8000->8000/tcp, 0.0.0.0:8081->8080/tcp   xnatmaster_xnat-web_1
61ea8d8d138b        xnatmaster_xnat-db      "docker-entrypoint.s…"   3 minutes ago       Exited (1) 6 seconds ago                                                    xnatmaster_xnat-db_1
PS C:\xnatmaster> docker-compose exec xnat-web bash
bash-4.4# su - postgres
su: can't change directory to '/var/lib/postgresql'
f439421c0d88:/$ psql
psql: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
f439421c0d88:/$ exit
bash-4.4# exit
exit
PS C:\xnatmaster>

Herrick, Rick

unread,
Dec 6, 2019, 12:29:01 PM12/6/19
to xnat_di...@googlegroups.com

Something’s going wrong during start-up of the PostgreSQL container. Whatever is wrong with it the first time is still wrong with it the second and third times, so that’s why the restarts are failing. Have a look at the logs for the container and see if there’s anything in there that indicates why it’s failing:

 

$ docker logs xnatmaster_xnat-db_1

 

 

-- 

Rick Herrick

Sr. Programmer/Analyst

Neuroinformatics Research Group

Washington University School of Medicine

Phone: +1 (314) 273-1645

--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xnat_discussion/24f1bec1-62ae-4ec4-b45c-a4a1b1bb2738%40googlegroups.com.

 


The materials in this message are private and may contain Protected Healthcare Information or other information of a sensitive nature. If you are not the intended recipient, be advised that any unauthorized use, disclosure, copying or the taking of any action in reliance on the contents of this information is strictly prohibited. If you have received this email in error, please immediately notify the sender via telephone or return mail.

Rj He

unread,
Dec 6, 2019, 2:21:24 PM12/6/19
to xnat_discussion
Hi, Rick,


I got following, just don't know how to fix it in windows;

PS C:\xnatmaster> docker logs xnatmaster_xnat-db_1

PostgreSQL Database directory appears to contain a database; Skipping initialization

FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.

PostgreSQL Database directory appears to contain a database; Skipping initialization

FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.

PostgreSQL Database directory appears to contain a database; Skipping initialization

FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
PS C:\xnatmaster>

To unsubscribe from this group and stop receiving emails from it, send an email to xnat_di...@googlegroups.com.

Herrick, Rick

unread,
Dec 6, 2019, 2:49:09 PM12/6/19
to xnat_di...@googlegroups.com

I think this is what you’re seeing:

 

https://github.com/docker/for-win/issues/3385

 

Try the fix described in there.

To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xnat_discussion/c9d956bf-3cd0-48e6-ac5c-1bfda6e63cf3%40googlegroups.com.

Rj He

unread,
Dec 6, 2019, 3:12:10 PM12/6/19
to xnat_discussion

Herrick, Rick

unread,
Dec 6, 2019, 3:15:51 PM12/6/19
to xnat_di...@googlegroups.com

There’s not really much I can do with that myself, since I don’t have a Windows machine to test it on. I think creating an external volume and mounting that seems like it would work, so give that a try!

To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xnat_discussion/45fd7181-3d51-4f64-93fa-bc4c2d9f05c1%40googlegroups.com.

Rj He

unread,
Dec 6, 2019, 3:49:12 PM12/6/19
to xnat_discussion

Hi, Rick,

Per the link I send you in last message, both ways of following would make postgre up and stay in windows:

either:
xnat-db:
    build: ./postgres
    expose:
      - "5432"
    volumes:
      - /var/lib/postgresql/data

or:
xnat-db:
    build: ./postgres
    expose:
      - "5432"
    volumes:
      - postgres-data:/var/lib/postgresql/data
with declaration:
volumes:
  postgres-data:


will generate output at the bottom, it seems now the problem is how to start the database server using:

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

how to do it?




PS C:\xnatmaster> docker container ls -a
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                                            NAMES
97ebafd704a9        xnatmaster_xnat-nginx   "nginx -g 'daemon of…"   7 seconds ago       Up 5 seconds        0.0.0.0:80->80/tcp                               xnatmaster_xnat-nginx_1
2206349557bc        xnatmaster_xnat-web     "wait-for-postgres.s…"   8 seconds ago       Up 6 seconds        0.0.0.0:8000->8000/tcp, 0.0.0.0:8081->8080/tcp   xnatmaster_xnat-web_1
72a59c6706e1        xnatmaster_xnat-db      "docker-entrypoint.s…"   10 seconds ago      Up 8 seconds        5432/tcp                                         xnatmaster_xnat-db_1
PS C:\xnatmaster> docker-compose logs -f --tail=20 xnat-web
Attaching to xnatmaster_xnat-web_1
xnat-web_1    |         Is the server running on host "localhost" (127.0.0.1) and accepting
xnat-web_1    |         TCP/IP connections on port 5432?
xnat-web_1    | could not connect to server: Address not available
xnat-web_1    |         Is the server running on host "localhost" (::1) and accepting
xnat-web_1    |         TCP/IP connections on port 5432?
xnat-web_1    | Postgres is unavailable - sleeping
xnat-web_1    | psql: could not connect to server: Connection refused
xnat-web_1    |         Is the server running on host "localhost" (127.0.0.1) and accepting
xnat-web_1    |         TCP/IP connections on port 5432?
xnat-web_1    | could not connect to server: Address not available
xnat-web_1    |         Is the server running on host "localhost" (::1) and accepting
xnat-web_1    |         TCP/IP connections on port 5432?
xnat-web_1    | Postgres is unavailable - sleeping
xnat-web_1    | psql: could not connect to server: Connection refused
xnat-web_1    |         Is the server running on host "localhost" (127.0.0.1) and accepting
xnat-web_1    |         TCP/IP connections on port 5432?
xnat-web_1    | could not connect to server: Address not available
xnat-web_1    |         Is the server running on host "localhost" (::1) and accepting
xnat-web_1    |         TCP/IP connections on port 5432?
xnat-web_1    | Postgres is unavailable - sleeping
xnat-web_1    | psql: could not connect to server: Connection refused
xnat-web_1    |         Is the server running on host "localhost" (127.0.0.1) and accepting
xnat-web_1    |         TCP/IP connections on port 5432?
xnat-web_1    | could not connect to server: Address not available
xnat-web_1    |         Is the server running on host "localhost" (::1) and accepting
xnat-web_1    |         TCP/IP connections on port 5432?
xnat-web_1    | Postgres is unavailable - sleeping
ERROR: Aborting.

PS C:\xnatmaster> docker logs xnatmaster_xnat-db_1
****************************************************
WARNING: No password has been set for the database.
         This will allow anyone with access to the
         Postgres port to access your database. In
         Docker's default configuration, this is
         effectively any other container on the same
         system.

         Use "-e POSTGRES_PASSWORD=password" to set
         it in "docker run".
****************************************************
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 ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... UTC
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /var/lib/postgresql/data/base/1 ... ok
initializing pg_authid ... ok
setting password ... ok
initializing dependencies ... ok
creating system views ... ok
sh: locale: not found
loading system objects' descriptions ... ok
creating collations ... ok
No usable system locales were found.
Use the option "--debug" to see details.
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

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


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.
waiting for server to start....LOG:  database system was shut down at 2019-12-06 20:39:44 UTC
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started
 done
server started

/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/XNAT.sql
CREATE ROLE
CREATE DATABASE
ALTER ROLE


LOG:  received fast shutdown request
LOG:  aborting any active transactions
LOG:  autovacuum launcher shutting down
waiting for server to shut down....LOG:  shutting down
LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

LOG:  database system was shut down at 2019-12-06 20:39:45 UTC
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started
PS C:\xnatmaster>










On Friday, December 6, 2019 at 1:49:09 PM UTC-6, Herrick, Rick wrote:

Herrick, Rick

unread,
Dec 6, 2019, 4:10:01 PM12/6/19
to xnat_di...@googlegroups.com

I don’t think you need to pass the -D xxx option into the container. Instead just mount the volume to the default data folder for the PostgreSQL container, which I believe is /var/lib/postgresql/data (at least that’s what it’s mounted to in the standard XNAT docker-compose configuration).

 

I don’t really trust that first configuration with just “- /var/lib/postgresql/data”, since I don’t know where that would mount from locally. I think the second configuration, mounting a defined volume that’s pre-configured, would be the best option.

To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xnat_discussion/dff59918-c5dc-4683-9039-057ff34811f5%40googlegroups.com.

Rj He

unread,
Dec 6, 2019, 4:47:36 PM12/6/19
to xnat_discussion

Thanks for the advice!
Reply all
Reply to author
Forward
0 new messages