Estou executando um aplicativo clojure que precisa acessar um banco de dados local. O aplicativo clojure está usando jdbc:
:dependencies [[org.clojure/clojure "1.10.0"]
...
[org.clojure/java.jdbc "0.7.12"]
[org.postgresql/postgresql "42.3.3"]]
O aplicativo funciona conforme o esperado quando executado diretamente em um host com uma versão do postgresql instalada, mesmo quando conectado a um banco de dados remoto.
No entanto, quando executado de dentro de um contêiner docker com base na clojure
imagem:
# syntax=docker/dockerfile:1
FROM clojure
WORKDIR /ui-service
COPY . .
CMD ["lein", "ring", "server-headless", "3000"]
EXPOSE 3000
Não consegue conectar:
lan-activity-ui-service-1 | org.postgresql.util.PSQLException: ERROR: could not load library "/usr/lib/postgresql/13/lib/llvmjit.so": /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /lib/x86_64-linux-gnu/libz3.so.4)
lan-activity-ui-service-1 | QueryExecutorImpl.java:2675 org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse
lan-activity-ui-service-1 | QueryExecutorImpl.java:2365 org.postgresql.core.v3.QueryExecutorImpl.processResults
lan-activity-ui-service-1 | QueryExecutorImpl.java:355 org.postgresql.core.v3.QueryExecutorImpl.execute
lan-activity-ui-service-1 | PgStatement.java:490 org.postgresql.jdbc.PgStatement.executeInternal
lan-activity-ui-service-1 | PgStatement.java:408 org.postgresql.jdbc.PgStatement.execute
lan-activity-ui-service-1 | PgPreparedStatement.java:166 org.postgresql.jdbc.PgPreparedStatement.executeWithFlags
lan-activity-ui-service-1 | PgPreparedStatement.java:118 org.postgresql.jdbc.PgPreparedStatement.executeQuery
lan-activity-ui-service-1 | jdbc.clj:1090 clojure.java.jdbc/execute-query-with-params
lan-activity-ui-service-1 | jdbc.clj:1084 clojure.java.jdbc/execute-query-with-params
lan-activity-ui-service-1 | jdbc.clj:1113 clojure.java.jdbc/db-query-with-resultset*
lan-activity-ui-service-1 | jdbc.clj:1093 clojure.java.jdbc/db-query-with-resultset*
lan-activity-ui-service-1 | jdbc.clj:1182 clojure.java.jdbc/query
lan-activity-ui-service-1 | jdbc.clj:1144 clojure.java.jdbc/query
lan-activity-ui-service-1 | jdbc.clj:1160 clojure.java.jdbc/query
lan-activity-ui-service-1 | jdbc.clj:1144 clojure.java.jdbc/query
lan-activity-ui-service-1 | db.clj:33 ui-service.db/all-devices
lan-activity-ui-service-1 | db.clj:32 ui-service.db/all-devices
lan-activity-ui-service-1 | handler.clj:21 ui-service.handler/fn
lan-activity-ui-service-1 | handler.clj:20 ui-service.handler/fn
lan-activity-ui-service-1 | core.clj:158 compojure.core/wrap-response[fn]
lan-activity-ui-service-1 | core.clj:128 compojure.core/wrap-route-middleware[fn]
lan-activity-ui-service-1 | core.clj:137 compojure.core/wrap-route-info[fn]
lan-activity-ui-service-1 | core.clj:146 compojure.core/wrap-route-matches[fn]
lan-activity-ui-service-1 | core.clj:185 compojure.core/routing[fn]
lan-activity-ui-service-1 | core.clj:2701 clojure.core/some
lan-activity-ui-service-1 | core.clj:2692 clojure.core/some
lan-activity-ui-service-1 | core.clj:185 compojure.core/routing
lan-activity-ui-service-1 | core.clj:182 compojure.core/routing
lan-activity-ui-service-1 | RestFn.java:139 clojure.lang.RestFn.applyTo
lan-activity-ui-service-1 | core.clj:667 clojure.core/apply
lan-activity-ui-service-1 | core.clj:660 clojure.core/apply
lan-activity-ui-service-1 | core.clj:192 compojure.core/routes[fn]
lan-activity-ui-service-1 | json.clj:102 ring.middleware.json/wrap-json-params[fn]
lan-activity-ui-service-1 | json.clj:143 ring.middleware.json/wrap-json-response[fn]
lan-activity-ui-service-1 | cors.clj:47 jumblerg.middleware.cors/allow-origins
lan-activity-ui-service-1 | cors.clj:41 jumblerg.middleware.cors/allow-origins
lan-activity-ui-service-1 | cors.clj:57 jumblerg.middleware.cors/wrap-cors[fn]
lan-activity-ui-service-1 | Var.java:384 clojure.lang.Var.invoke
lan-activity-ui-service-1 | reload.clj:39 ring.middleware.reload/wrap-reload[fn]
lan-activity-ui-service-1 | stacktrace.clj:26 ring.middleware.stacktrace/wrap-stacktrace-log[fn]
lan-activity-ui-service-1 | stacktrace.clj:96 ring.middleware.stacktrace/wrap-stacktrace-web[fn]
lan-activity-ui-service-1 | jetty.clj:25 ring.adapter.jetty/proxy-handler[fn]
lan-activity-ui-service-1 | (Unknown Source) ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle
lan-activity-ui-service-1 | HandlerWrapper.java:97 org.eclipse.jetty.server.handler.HandlerWrapper.handle
lan-activity-ui-service-1 | Server.java:499 org.eclipse.jetty.server.Server.handle
lan-activity-ui-service-1 | HttpChannel.java:311 org.eclipse.jetty.server.HttpChannel.handle
lan-activity-ui-service-1 | HttpConnection.java:258 org.eclipse.jetty.server.HttpConnection.onFillable
lan-activity-ui-service-1 | AbstractConnection.java:544 org.eclipse.jetty.io.AbstractConnection$2.run
lan-activity-ui-service-1 | QueuedThreadPool.java:635 org.eclipse.jetty.util.thread.QueuedThreadPool.runJob
lan-activity-ui-service-1 | QueuedThreadPool.java:555 org.eclipse.jetty.util.thread.QueuedThreadPool$3.run
lan-activity-ui-service-1 | Thread.java:833 java.lang.Thread.run
Como posso garantir que as dependências necessárias estejam disponíveis no contêiner docker? Preciso usar uma compilação docker de vários estágios para incluir a imagem postgresql? Ou é possível adicionar as dependências necessárias puramente em java/clojure?
Consegui construir um contêiner incluindo o /usr/lib/postgresql/13/
diretório e o /usr/lib/postgresql/13/lib/llvmjit.so
arquivo que o clojure estava procurando, mas estranhamente ainda recebo o erro ERROR: could not load library "/usr/lib/postgresql/13/lib/llvmjit.so"
::
# syntax=docker/dockerfile:1
FROM postgres:13 as postgres
FROM clojure
WORKDIR /ui-service
COPY . .
COPY --from=postgres /usr/lib/postgresql/ /usr/lib/postgresql/
RUN ls -l /usr/lib/postgresql/13/lib/llvmjit.so
CMD ["lein", "ring", "server-headless", "3000"]
EXPOSE 3000