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.

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法