@@ -216,7 +216,11 @@ func createContainer(ctx context.Context, docker *client.Client, image string, p
216
216
}
217
217
218
218
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 )
220
224
}
221
225
222
226
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
247
251
})
248
252
249
253
if err != nil {
254
+ log .Dbg (out )
250
255
return fmt .Errorf ("failed to reset pg_hba.conf: %w" , err )
251
256
}
252
257
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
+ }
254
275
255
276
return nil
256
277
}
0 commit comments