@@ -11,16 +11,18 @@ import (
1111
1212 "github.com/docker/docker/api/types/container"
1313 "github.com/docker/docker/api/types/image"
14+ "github.com/docker/docker/api/types/volume"
1415 "github.com/docker/docker/client"
1516 "github.com/docker/go-connections/nat"
1617 _ "github.com/jackc/pgx/v5/stdlib"
1718 "github.com/spf13/cobra"
1819)
1920
2021const (
21- containerName = "dbos-db"
22- imageName = "pgvector/pgvector:pg16"
23- pgData = "/var/lib/postgresql/data"
22+ containerName = "dbos-db"
23+ imageName = "pgvector/pgvector:pg16"
24+ pgData = "/var/lib/postgresql/data"
25+ hostPgDataVolumeName = "pgdata"
2426)
2527
2628var postgresCmd = & cobra.Command {
@@ -147,6 +149,10 @@ func startDockerPostgres() error {
147149 },
148150 }
149151
152+ _ , err = cli .VolumeCreate (ctx , volume.CreateOptions {Name : hostPgDataVolumeName })
153+ if err != nil {
154+ return fmt .Errorf ("failed to create volume %s for Postgres: %w" , hostPgDataVolumeName , err )
155+ }
150156 hostConfig := & container.HostConfig {
151157 PortBindings : nat.PortMap {
152158 "5432/tcp" : []nat.PortBinding {
@@ -157,6 +163,9 @@ func startDockerPostgres() error {
157163 },
158164 },
159165 AutoRemove : true ,
166+ Binds : []string {
167+ fmt .Sprintf ("%s:%s" , hostPgDataVolumeName , pgData ),
168+ },
160169 }
161170
162171 resp , err := cli .ContainerCreate (ctx , config , hostConfig , nil , nil , containerName )
0 commit comments