GoLang postgres testcontainers 初始化脚本不起作用
GoLang postgres testcontainers init script doesn't work
我想用初始化脚本启动 postgres 容器。
request := testcontainers.ContainerRequest{
Image: "postgres:14.1-alpine",
Entrypoint: nil,
Env: map[string]string{
"POSTGRES_DB": "postgres",
"PGUSER": "postgres",
"POSTGRES_PASSWORD": "postgres",
//"PGDATA": "postgres",
},
ExposedPorts: []string{"5432"},
BindMounts: map[string]string{
"/media/mihovelgod/Новый том1/GoProjects/microservices/sql/go-sql/resources/migrations": "/docker-entrypoint-initdb.d",
},
Name: "postgres",
User: "postgres",
WaitingFor: wait.ForLog("database system is ready to accept connections"),
AutoRemove: true,
}
container, err = testcontainers.GenericContainer(
test.CTX,
testcontainers.GenericContainerRequest{
ContainerRequest: request,
Started: true,
},
)
if err != nil {
log.Panicln(err)
}
我在 log.Panicln(错误)中收到以下恐慌消息:
failed to create container
Error response from daemon
invalid mount config for type "bind": bind source path does not exist: /docker-entrypoint-initdb.d
重点是它在 docker-compose.yml 期间完美运行。
如何解决这个问题?
查看 the source,似乎 TestContainers 想要 container_path: host_path
在 BindMounts
中。如果你尝试会发生什么:
BindMounts: map[string]string{
"/docker-entrypoint-initdb.d": "/media/mihovelgod/Новый том1/GoProjects/microservices/sql/go-sql/resources/migrations",
},
似乎较新版本的 TestContainers 已完全删除 BindMounts
并用更通用的 Mounts
字段取而代之。
我想用初始化脚本启动 postgres 容器。
request := testcontainers.ContainerRequest{
Image: "postgres:14.1-alpine",
Entrypoint: nil,
Env: map[string]string{
"POSTGRES_DB": "postgres",
"PGUSER": "postgres",
"POSTGRES_PASSWORD": "postgres",
//"PGDATA": "postgres",
},
ExposedPorts: []string{"5432"},
BindMounts: map[string]string{
"/media/mihovelgod/Новый том1/GoProjects/microservices/sql/go-sql/resources/migrations": "/docker-entrypoint-initdb.d",
},
Name: "postgres",
User: "postgres",
WaitingFor: wait.ForLog("database system is ready to accept connections"),
AutoRemove: true,
}
container, err = testcontainers.GenericContainer(
test.CTX,
testcontainers.GenericContainerRequest{
ContainerRequest: request,
Started: true,
},
)
if err != nil {
log.Panicln(err)
}
我在 log.Panicln(错误)中收到以下恐慌消息:
failed to create container
Error response from daemon
invalid mount config for type "bind": bind source path does not exist: /docker-entrypoint-initdb.d
重点是它在 docker-compose.yml 期间完美运行。 如何解决这个问题?
查看 the source,似乎 TestContainers 想要 container_path: host_path
在 BindMounts
中。如果你尝试会发生什么:
BindMounts: map[string]string{
"/docker-entrypoint-initdb.d": "/media/mihovelgod/Новый том1/GoProjects/microservices/sql/go-sql/resources/migrations",
},
似乎较新版本的 TestContainers 已完全删除 BindMounts
并用更通用的 Mounts
字段取而代之。