【问题标题】:GoLang postgres testcontainers init script doesn't workGoLang postgres testcontainers 初始化脚本不起作用
【发布时间】:2022-02-01 06:20:33
【问题描述】:

我想用初始化脚本启动 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(err) 中收到以下恐慌消息:

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 中完美运行。 如何解决这个问题?

【问题讨论】:

  • 在末尾添加斜线:/docker-entrypoint-initdb.d/
  • @serge-v 没有帮助,得到了同样的恐慌信息

标签: docker go docker-compose testcontainers


【解决方案1】:

查看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 字段替换它。

【讨论】:

  • 这对我来说非常有用,非常感谢!
猜你喜欢
  • 1970-01-01
  • 2014-03-30
  • 2011-10-01
  • 2021-08-18
  • 1970-01-01
  • 2015-04-27
  • 1970-01-01
  • 1970-01-01
  • 2014-09-17
相关资源
最近更新 更多