登录
首页 >  Golang >  Go问答

GoLang postgres testcontainers 初始化脚本无效化

来源:stackoverflow

时间:2024-02-08 17:51:21 126浏览 收藏

大家好,我们又见面了啊~本文《GoLang postgres testcontainers 初始化脚本无效化》的内容中将会涉及到等等。如果你正在学习Golang相关知识,欢迎关注我,以后会给大家带来更多Golang相关文章,希望我们能一起进步!下面就开始本文的正式内容~

问题内容

我想使用 init 脚本启动 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 中完美运行。 如何解决这个问题?


正确答案


查看 the source,testcontainers 似乎想要 container_path: bindmounts 中的 host_path。如果您尝试会发生什么:

BindMounts: map[string]string{
             "/docker-entrypoint-initdb.d": "/media/mihovelgod/Новый том1/GoProjects/microservices/sql/go-sql/resources/migrations",
        },

看起来最新版本的 testcontainers 已完全删除 bindmounts 并用更通用的 mounts 字段替换。

今天带大家了解了的相关知识,希望对你有所帮助;关于Golang的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>