douxu2081 2018-08-14 08:35
浏览 232

在Docker容器中运行go二进制文件时找不到Spatialite扩展

I am setting up a Spatialite database (SQLite + Spatialite extension) and an associated Go program running in a docker container that queries the database and returns data.

Go-spatialite, in my understanding will dynamically load the spatialite library at runtime in order to query the database. Everything runs fine when running the Go program locally and querying the service with Postman.

However, when using the container, the Go program fails to find the spatialite extension:

"error":"shaxbee/go-spatialite: spatialite extension not found."

I use go-spatialite (shaxbee) package and database/sql package. I have installed Spatialite locally.

I open the database connection like this:

db, err := sql.Open("spatialite", "path/to/my/db")
if err != nil {
    logVar.WithError(err).Fatal("Impossible to open database")
}
if err := db.Ping(); err != nil {
    logVar.WithError(err).Fatal("Cannot connect to database")
}

I used this Dockerfile to adapt mine (that is based on alpine-glibc) in order to install the Spatialite library during image building. According to the Spatialite package, it looks for different for spatialite library and load it.

When checking /usr/local/lib/ in the container, the libraries are there:

libspatialite.a
libspatialite.la
libspatialite.so
libspatialite.so.7
libspatialite.so.7.1.0
libsqlite3.so
libsqlite3.so.0
libsqlite3.so.0.8.6

It seems to me that the program does not know where to get the libraries. Do you have any ideas ?

Thanks

  • 写回答

1条回答 默认 最新

  • dongzhanyan3667 2018-08-14 15:15
    关注

    That Dockerfile sets up a container with libspatialite version 4.3.0a.

    ...
    
    RUN wget "http://www.gaia-gis.it/gaia-sins/freexl-1.0.4.tar.gz" && tar zxvf freexl-1.0.4.tar.gz && cd freexl-1.0.4 && ./configure && make && make install
    
    RUN wget "http://www.gaia-gis.it/gaia-sins/libspatialite-4.3.0a.tar.gz" && tar zxvf libspatialite-4.3.0a.tar.gz && cd libspatialite-4.3.0a && ./configure && make && make install
    
    RUN wget "http://www.gaia-gis.it/gaia-sins/readosm-1.1.0.tar.gz" && tar zxvf readosm-1.1.0.tar.gz && cd readosm-1.1.0 && ./configure && make && make install
    
    RUN wget "http://www.gaia-gis.it/gaia-sins/spatialite-tools-4.3.0.tar.gz" && tar zxvf spatialite-tools-4.3.0.tar.gz && cd spatialite-tools-4.3.0 && ./configure && make && make install
    ...
    

    From one of the recent commits to go-spatialite, we can see that the required version is 5.

    var LibNames = []entrypoint{
        {"mod_spatialite", "sqlite3_modspatialite_init"},
        {"libspatialite.so", "sqlite3_modspatialite_init"},
        {"libspatialite.so.5", "spatialite_init_ex"},
        {"libspatialite.so", "spatialite_init_ex"},
    }
    

    (spatialite.go)

    Use a container with version 5 of libspatialite to resolve your issue.

    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作