Search code examples
dockerpostgrest

How to use a second docker instance?


Assuming that the command for a second docker instance is

docker run --rm --net=host -p 3002:3002 -e SERVER_PORT="3002" \
 -e PGRST_DB_URI="postgres://postgres@localhost/prod2"    \
 -e PGRST_DB_ANON_ROLE="postgres" postgrest/postgrest

it results

WARNING: Published ports are discarded when using host network mode
Attempting to connect to the database...
Listening on port 3000
postgrest: Network.Socket.bind: resource busy (Address already in use)

That makes no sense because using -p 3002:3002 -e SERVER_PORT="3002"... Is it possible to run? Where is the configuration error?

NOTE: the first docker was implemented by docker run -d --net=host -p 3000:3000 -e PGRST_DB_URI="postgres://postgres@localhost/prod0" -e PGRST_DB_ANON_ROLE="postgres" postgrest/postgrest


See also https://github.com/PostgREST/postgrest/issues/1442


Solution

  • I think you just misspelled the server port environment variable name, you're missing PGRST from the beginning in the second command.

    Use -e PGRST_SERVER_PORT=3002 instead of -e SERVER_PORT.

    You get a warning because -p is ignored when using network host, but that does not seem to be an issue. Anyway, you can remove the -p settings from the commands and use just --net=host.