Docker容器运行TileServer-GL时缺失libGLX.so.0依赖报错求助
TileServer-GL容器启动失败:libGLX.so.0缺失问题解决
问题描述
使用指定Dockerfile构建镜像后,启动容器时出现如下错误:
node:internal/modules/cjs/loader:1473 return process.dlopen(module, path.toNamespacedPath(filename)); ^ Error: libGLX.so.0: cannot open shared object file: No such file or directory at Module._extensions..node (node:internal/modules/cjs/loader:1473:18) at Module.load (node:internal/modules/cjs/loader:1207:32) at Module._load (node:internal/modules/cjs/loader:1023:12) at Module.require (node:internal/modules/cjs/loader:1235:19) at require (node:internal/modules/helpers:176:18) at Object.<anonymous> (/usr/lib/node_modules/tileserver-gl/node_modules/@maplibre/maplibre-gl-native/platform/node/index.js:5:12) at Module._compile (node:internal/modules/cjs/loader:1376:14) at Module._extensions..js (node:internal/modules/cjs/loader:1435:10) at Module.load (node:internal/modules/cjs/loader:1207:32) at Module._load (node:internal/modules/cjs/loader:1023:12) { code: 'ERR_DLOPEN_FAILED' } Node.js v20.11.1
原Dockerfile内容:
# Use an Ubuntu base image FROM ubuntu:latest # Install dependencies RUN apt-get update && \ apt-get install -y wget curl git unzip build-essential python3 # Install Node.js RUN curl -sL https://deb.nodesource.com/setup_20.x | bash - && \ apt-get install -y nodejs # Clone TileServer-GL repository RUN git clone https://github.com/klokantech/tileserver-gl.git /tileserver-gl # Change working directory WORKDIR /tileserver-gl # Install TileServer-GL dependencies RUN npm install RUN npm install -g npm@10.5.0 RUN npm install -g tileserver-gl WORKDIR / COPY ./config.json /config.json COPY ./test.mbtiles /test.mbtiles COPY templates /templates COPY styles /styles COPY fonts /fonts # Expose the default TileServer-GL port EXPOSE 8080 ENV PORT 8080 ENTRYPOINT ["tileserver-gl"] CMD "tileserver-gl --file test.mbtiles"
解决方案
1. 安装缺失的OpenGL系统库
libGLX.so.0是OpenGL核心依赖库,需在Dockerfile的依赖安装步骤中添加libgl1-mesa-glx和libgl1-mesa-dri两个包。
2. 修正ENTRYPOINT与CMD的执行逻辑
原配置中ENTRYPOINT和CMD的组合会导致命令执行错误:ENTRYPOINT指定了可执行文件,CMD应传递参数而非完整命令。需将CMD改为参数数组形式。
修改后的完整Dockerfile
# Use an Ubuntu base image FROM ubuntu:latest # Install dependencies including OpenGL libraries RUN apt-get update && \ apt-get install -y wget curl git unzip build-essential python3 libgl1-mesa-glx libgl1-mesa-dri # Install Node.js RUN curl -sL https://deb.nodesource.com/setup_20.x | bash - && \ apt-get install -y nodejs # Clone TileServer-GL repository RUN git clone https://github.com/klokantech/tileserver-gl.git /tileserver-gl # Change working directory WORKDIR /tileserver-gl # Install TileServer-GL dependencies RUN npm install RUN npm install -g npm@10.5.0 RUN npm install -g tileserver-gl WORKDIR / COPY ./config.json /config.json COPY ./test.mbtiles /test.mbtiles COPY templates /templates COPY styles /styles COPY fonts /fonts # Expose the default TileServer-GL port EXPOSE 8080 ENV PORT 8080 ENTRYPOINT ["tileserver-gl"] CMD ["--file", "test.mbtiles"]
验证步骤
- 重新构建镜像:
docker build -t tiler_test -f Dockerfile .
- 启动容器:
docker run -p 8080:8080 tiler_test:latest
容器启动后,可通过http://localhost:8080访问TileServer-GL服务。
内容的提问来源于stack exchange,提问作者Jake D
相关产品推荐
相关产品推荐

