@@ -216,7 +216,11 @@ func createContainer(ctx context.Context, docker *client.Client, image string, p
216216 }
217217
218218 if err := resetHBA (ctx , docker , containerID ); err != nil {
219- return "" , fmt .Errorf ("failed to init Postgres: %w" , err )
219+ return "" , fmt .Errorf ("failed to prepare pg_hba.conf: %w" , err )
220+ }
221+
222+ if err := setListenAddresses (ctx , docker , containerID ); err != nil {
223+ return "" , fmt .Errorf ("failed to set listen_addresses: %w" , err )
220224 }
221225
222226 if err := tools .StartPostgres (ctx , docker , containerID , tools .DefaultStopTimeout ); err != nil {
@@ -247,10 +251,27 @@ func resetHBA(ctx context.Context, dockerClient *client.Client, containerID stri
247251 })
248252
249253 if err != nil {
254+ log .Dbg (out )
250255 return fmt .Errorf ("failed to reset pg_hba.conf: %w" , err )
251256 }
252257
253- log .Dbg (out )
258+ return nil
259+ }
260+
261+ func setListenAddresses (ctx context.Context , dockerClient * client.Client , containerID string ) error {
262+ command := []string {"sh" , "-c" , `su postgres -c "echo listen_addresses = \'*\' >> ${PGDATA}/postgresql.conf"` }
263+
264+ log .Dbg ("Set listen addresses" , command )
265+
266+ out , err := tools .ExecCommandWithOutput (ctx , dockerClient , containerID , types.ExecConfig {
267+ Tty : true ,
268+ Cmd : command ,
269+ })
270+
271+ if err != nil {
272+ log .Dbg (out )
273+ return fmt .Errorf ("failed to set listen addresses: %w" , err )
274+ }
254275
255276 return nil
256277}
0 commit comments