Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpine support - musl libc #217

Closed
willfarrell opened this issue Jan 17, 2017 · 31 comments
Closed

Alpine support - musl libc #217

willfarrell opened this issue Jan 17, 2017 · 31 comments

Comments

@willfarrell
Copy link

I'm getting the following error while attempting to run the example on alpine.

/var/www/node_modules/bindings/bindings.js:83
        throw e
        ^

Error: Error relocating /var/www/node_modules/ibm_db/build/Release/../../installer/clidriver/lib/libdb2.so.1: pthread_mutexattr_setkind_np: symbol not found
    at Object.Module._extensions..node (module.js:598:18)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at bindings (/var/www/node_modules/bindings/bindings.js:76:44)
    at Object.<anonymous> (/var/www/node_modules/ibm_db/lib/odbc.js:27:31)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)

The file does exist at: /var/www/node_modules/ibm_db/installer/clidriver/lib/libdb2.so.1.

Source:
Dockerfile

FROM node:7-alpine

RUN apk add --no-cache --virtual .build-deps \
    python make g++

RUN mkdir /var/www \
    && cd /var/www \
    && npm install ibm_db

RUN apk del .build-deps

RUN apk add --no-cache --virtual .odbc-rundeps \
        libgcrypt \
        linux-pam \
        libxml2 \
    && ln -s -f /usr/lib/libgcrypt.so.20 /usr/lib/libcrypt.so.1

COPY ./app.js /var/www/

CMD [ "node", "/var/www/app.js" ]

app.js

var ibmdb = require('ibm_db');

ibmdb.open("DATABASE=Test;HOSTNAME=*******;UID=******;PWD=******;PORT=446;PROTOCOL=TCPIP", function (err,conn) {
	if (err) return console.log(err);

	conn.query('***********', function (err, data) {
		if (err) console.log(err);
		else console.log(data);

		conn.close(function () {
			console.log('done');
		});
	});
});
@bimalkjha
Copy link
Member

bimalkjha commented Jan 17, 2017

Ok. So, the problem is this error:

Error: Error relocating /var/www/node_modules/ibm_db/build/Release/../../installer/clidriver/lib/libdb2.so.1: pthread_mutexattr_setkind_np: symbol not found
    at Object.Module._extensions..node (module.js:598:18)

While loading libdb2.so.1, OS does not find the symbol pthread_mutexattr_setkind_np.
I searched for it on my linux system and found that pthread_mutexattr_setkind_np should be in glibc library:

$ nm libdb2.so.1 | grep pthread_mutexattr_setkind_np
U pthread_mutexattr_setkind_np@@GLIBC_2.2.5

Please share output of ldd libdb2.so.1 command. Also, node -v result. Thanks.

@willfarrell
Copy link
Author

I added in glibc to see if that solved it. Same result.

For those looking for how to do it:

RUN cd /tmp \
    && wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub \
    && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.23-r3/glibc-2.23-r3.apk \
    && apk add --no-cache glibc-2.23-r3.apk

NodeJS: v7.4.0
npm: v4.0.5

$ docker run odbc ldd /var/www/node_modules/ibm_db/installer/clidriver/lib/libdb2.so.1
Error relocating /var/www/node_modules/ibm_db/installer/clidriver/lib/libdb2.so.1: pthread_mutexattr_setkind_np: symbol not found
Error relocating /var/www/node_modules/ibm_db/installer/clidriver/lib/libdb2.so.1: __strtof_internal: symbol not found
Error relocating /var/www/node_modules/ibm_db/installer/clidriver/lib/libdb2.so.1: pthread_attr_setaffinity_np: symbol not found
Error relocating /var/www/node_modules/ibm_db/installer/clidriver/lib/libdb2.so.1: __register_atfork: symbol not found
Error relocating /var/www/node_modules/ibm_db/installer/clidriver/lib/libdb2.so.1: __strtod_internal: symbol not found
Error relocating /var/www/node_modules/ibm_db/installer/clidriver/lib/libdb2.so.1: sysctl: symbol not found
Error relocating /var/www/node_modules/ibm_db/installer/clidriver/lib/libdb2.so.1: backtrace: symbol not found
Error relocating /var/www/node_modules/ibm_db/installer/clidriver/lib/libdb2.so.1: getgrent_r: symbol not found
Error relocating /var/www/node_modules/ibm_db/installer/clidriver/lib/libdb2.so.1: __res_init: symbol not found
Error relocating /var/www/node_modules/ibm_db/installer/clidriver/lib/libdb2.so.1: dlvsym: symbol not found
	ldd (0x5608749ab000)
	libcrypt.so.1 => /usr/lib/libcrypt.so.1 (0x7f336255c000)
	libdl.so.2 => ldd (0x5608749ab000)
	libpthread.so.0 => ldd (0x5608749ab000)
	librt.so.1 => ldd (0x5608749ab000)
	libpam.so.0 => /lib/libpam.so.0 (0x7f3362350000)
	libxml2.so.2 => /usr/lib/libxml2.so.2 (0x7f3362025000)
	libm.so.6 => ldd (0x5608749ab000)
	libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7f3361cd5000)
	libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7f3361ac2000)
	libc.so.6 => ldd (0x5608749ab000)
	libgpg-error.so.0 => /usr/lib/libgpg-error.so.0 (0x7f33618b1000)
	libz.so.1 => /lib/libz.so.1 (0x7f336169b000)

@bimalkjha
Copy link
Member

So, your alpine OS has below missing libraries:

libdl.so.2 => ldd (0x5608749ab000)
libpthread.so.0 => ldd (0x5608749ab000)
librt.so.1 => ldd (0x5608749ab000)
libm.so.6 => ldd (0x5608749ab000)
libc.so.6 => ldd (0x5608749ab000)

On my Linux system I can see these libs under /lib64:

        libdl.so.2 => /lib64/libdl.so.2 (0x00002aaaae2c9000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00002aaaae3cd000)
        librt.so.1 => /lib64/librt.so.1 (0x00002aaaae4e7000)
        libm.so.6 => /lib64/libm.so.6 (0x00002aaaae940000)
        libc.so.6 => /lib64/libc.so.6 (0x00002aaaaeda1000)

Please contact docker team and get these libs. Now, I am curious to know - after installing ibm_db, which server you want to connect? None of the IBM DB2 or DashDB driver would work on this system with missing libraries. It is not an issue with node-ibm_db driver. Thanks.

@willfarrell
Copy link
Author

Looks like it's related to this: https://github.com/gliderlabs/docker-alpine/blob/master/docs/caveats.md#incompatible-binaries

I'll dig deeper and post a solution when I find one. Thank you for the assistance.

@willfarrell
Copy link
Author

For other running into this. Checkout: gliderlabs/docker-alpine#11 (comment) and https://github.com/frol/docker-alpine-glibc/blob/master/Dockerfile

One of two things needs to happen for this to work.

  1. compile your own version of node on glibc
  2. compile imb_db2 deps for musl libc

The later seems like the better approach, but could take awhile to figure out how to do it.

@willfarrell willfarrell changed the title pthread_mutexattr_setkind_np: symbol not found Alpine support - musl libc Jan 17, 2017
@willfarrell
Copy link
Author

willfarrell commented Jan 18, 2017

@hwangbible do you remember how you resolve your issue at gliderlabs/docker-alpine#11 (comment) ?

@bimalkjha
Copy link
Member

@willfarrell I would suggest to install musl libc library and check file /usr/lib/libc.so.6 is available or not. If libc.so.6 is available, then run ldd libdb2.so.1 and see it is able to find the library or not. Thanks.

@willfarrell
Copy link
Author

willfarrell commented Jan 18, 2017

musl libc is install by default on alpine. Which is giving us what we've been seeing above.

$ ldd /var/www/node_modules/ibm_db/installer/clidriver/lib/libdb2.so.1
ldd (0x5630cd73b000)
	libcrypt.so.1 => /usr/lib/libcrypt.so.1 (0x7f991cd7f000)
	libdl.so.2 => ldd (0x5630cd73b000)
	libpthread.so.0 => ldd (0x5630cd73b000)
	librt.so.1 => ldd (0x5630cd73b000)
	libpam.so.0 => /lib/libpam.so.0 (0x7f991cb73000)
	libxml2.so.2 => /usr/lib/libxml2.so.2 (0x7f991c848000)
	libm.so.6 => ldd (0x5630cd73b000)
	libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7f991c4f8000)
	libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7f991c2e5000)
	libc.so.6 => ldd (0x5630cd73b000)
	libgpg-error.so.0 => /usr/lib/libgpg-error.so.0 (0x7f991c0d4000)
	libz.so.1 => /lib/libz.so.1 (0x7f991bebe000)

For what I'm understanding, ldd on alpine is built on musl libc and thus is unable to findlibc.so.6 that is now included w/ glibc. There is a seperate ldd included with the glibc package however it doesn't support dynamic libraries (it's a sh script). Is it possible to have IBM compile the binary against musl libc? Alpine is a growing environment with the increasing use of smaller and smaller docker containers.

@bimalkjha
Copy link
Member

Is it possible to have IBM compile the binary against musl libc?
--> There is no such plan as of now. Thanks.

@bimalkjha
Copy link
Member

Closing the issue as IBM ODBC/CLI driver is not supported on Alpine Linux and hence ibm_db can not work on Alpine. Checked with Kelly Rodger at IBM and he confirmed that Alpine Linux is not a supported platform for DB2. Thanks.

@kentonbmax
Copy link

If not alpine what is a super lightweight linux container docker image to use?

@bimalkjha
Copy link
Member

@kentonbmax You can use Ubuntu docker image. Thanks.

@kentonbmax
Copy link

Hey, I had difficulty with the ubuntu image and tried the oracle linux image (smaller). it works but am getting license issue that I commented on in a different issue.

@bimalkjha
Copy link
Member

@kentonbmax Could you please paste the error about license issue here? that would help to understand the problem. Also, let me know your database is on which OS? License file is required only if your DB2 server is installed on z/OS or i-Series systems. Thanks.

@kentonbmax
Copy link

DB Server: i-series.
Container: Oracle Linux
{ Error: [IBM][CLI Driver] SQL1598N An attempt to connect to the database server failed because of a licensing problem. SQLSTATE=42968

errors: [],
error: '[node-odbc] SQL_ERROR',
message: '[IBM][CLI Driver] SQL1598N An attempt to connect to the database server failed because of a licensing problem. SQLSTATE=42968\n',
state: '42968' }

@bimalkjha
Copy link
Member

@kentonbmax You need to copy db2connect license file under ibm_db/installer/clidriver/license folder to access i-Series server using ibm_db. Please contact your i-series system adminstrator or IBM support to get the db2connect license file. The license file name should be like db2con*.lic . Thanks.

@kentonbmax
Copy link

kentonbmax commented May 31, 2018 via email

@bimalkjha
Copy link
Member

@kentonbmax First check the db2level output of your windows system where this .lic file was working. If it is not DB2 V10.5, please get a db2 v10.5 license file.
Second, delete existing clidriver/cfgcache/conlic.bin file and then try connection if you have the correct license file. On windows, we can find cfgcache folder under C:\ProgramData\IBM\DB2<install_copy> folder.
If you are still facing issue, please update the connection string in ibm_db\installer\testODBCConnection.sh file near line no 29 for db2cli validate command and execute testODBCConnection.sh file. If it fails, share the generated files for investigation.
Thanks.

@kentonbmax
Copy link

kentonbmax commented Jun 4, 2018 via email

@bimalkjha
Copy link
Member

@kentonbmax If you already have Db2 V11.1 installed in your system, please share the output of "db2level" command.
The v11.1 license file will not work with ibm_db, but you can tell ibm_db to use pre-installed db2 v11.1 by setting IBM_DB_HOME env variable. Setting up the env var in linux is not necessary. Thanks.

@kentonbmax
Copy link

kentonbmax commented Jun 4, 2018 via email

@kentonbmax
Copy link

kentonbmax commented Jun 4, 2018 via email

@bimalkjha
Copy link
Member

@kentonbmax Please note that the license file that you have is for db2 v11.1 and it will not work with ibm_db which uses DB2 v10.5. You need a db2 v10.5 db2connect license file for ibm_db.

The ibm_data_server_driver_for_odbc_cli_linuxx64_v11.1.tar.gz that you are trying to use does not come with include folder and it do not have any header files. So, you can not use it with any other open source driver like node-ibm_db or python-ibm_db. Its a wrong version of clidriver that get packaged with .net-core without header files. If ibm_data_server_driver_for_odbc_cli_linuxx64_v11.1.tar.gz would have include folder, then you should be able to use ibm_db with this clidriver and current license file. Hope, you'll understand the difference.

Please tell .net-core team to use clidriver from https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli or keep include folder too with the clidriver that they ship with .net-core.

Unset IBM_DB_HOME using : export IBM_DB_HOME=
npm install ibm_db
get license file for DB2 V10.5fp6
copy 10.5 license file under ibm_db/installer/clidriver/license folder

Thanks.

@kentonbmax
Copy link

kentonbmax commented Jun 5, 2018 via email

@kentonbmax
Copy link

kentonbmax commented Jun 6, 2018 via email

@bimalkjha
Copy link
Member

@kentonbmax There seems some confusion. Lets talk about Windows first. You have not shared the complete output of db2level command and hence, we do not get complete info. The Install location and copy name is missing which gives more info about the product in use. See a sample db2level output that I get:

DB21085I  This instance or install (instance name, where applicable: "DB2")
uses "64" bits and DB2 code release "SQL11013" with level identifier
"0204010F".
Informational tokens are "DB2 v11.1.3030.148", "s1712010100",
"DYN1712010100WIN64", and Fix Pack "3".
Product is installed at "C:\PROGRA~1\IBM\SQLLIB" with DB2 Copy Name "DB2COPY1".

Seems, you are using DB2 v11.1.2 on Windows and you have license file for DB2 v11.1.2 too. Once you connect using the license file to i-Series, license check happens after 7 days only from that client.
If you have never used license file on Windows to connect to i-Series, means server is configured to accept connection from this Windows client without client side license. Note that if server is configured to accept connection from your Windows system, then no db2connect license is required on your Windows system.

Now about linux: seems your i-Series server is not configured to accept connection from this linux system. So, you need to apply license at client side. The expectation is clear: Either activate license on server to accept connection from client or apply license file at client side. You may check with your sysadmin with the error that you get on linux and ask him to enable the connection from your linux client. Thanks.

@tatemz
Copy link

tatemz commented Feb 21, 2019

It's prolly a good idea to support musl Alpine environment... It's really tiny and awesome

@VizorKit
Copy link

@willfarrell what did you end up doing? I'm facing the same issue and would prefer to use the alpine image as it is the company standard.

@bimalkjha
Copy link
Member

node-ibm_db works on Linux-x86-64 images of amazonlinux, ubuntu and debian. It can not work on alpile as IBM Db2 Client Installers are not compiled on alpine linux using musl libc. So, none of the IBM Driver for Db2 will work on alpine linux. Thanks.

@sliekens
Copy link

+1 for adding Alpine support.

@stijwilliams
Copy link

stijwilliams commented Aug 27, 2020

Another +1 for alpine support.. If your goal is to build secure containers, ubuntu and debian fail to meet the requirement with all the bloat they include.

Install scan tools

See https://github.com/aquasecurity/trivy

RUN apk add curl
&& curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/master/contrib/install.sh | sh -s -- -b /usr/local/bin
&& trivy --no-progress --download-db-only

This will fail the docker image build if there are problems

RUN trivy filesystem --exit-code 1 --no-progress /

^^ This is secure, run the same on the other base images, and you will see all sorts of security vulnerabilities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants