1

I am trying to run my app on the Docker. One of the library I am using is https://www.npmjs.com/package/odbc. In order to install that lib I need to meet the requirements described in the odbc readme:

  • unixODBC binaries and development libraries for module compilation
    • on Ubuntu/Debian sudo apt-get install unixodbc unixodbc-dev
    • on RedHat/CentOS sudo yum install unixODBC unixODBC-devel
  • odbc drivers for target database
  • properly configured odbc.ini and odbcinst.ini.

As per Microsoft doc in order to install ODBC Driver 13 for SQL Server https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017#ubuntu-1604-1 I manage to install all the stuff locally on my Mac and successfully connect with the SQL Server on Azure but still have some issues with installing them on the Docker and then run on VSTS. My Dockerfile:

FROM ubuntu:16.04
USER root
RUN apt-get update
RUN apt-get install --yes curl
RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
RUN apt-get install --yes nodejs
RUN apt-get install --yes build-essential
RUN apt-get install -y npm 
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get install -y build-essential
RUN apt-get install -y make
RUN apt-get install apt-transport-https
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql unixodbc-dev
ADD . /var/www/app
WORKDIR /var/www/app
RUN npm install && \
    npm cache clean --force
RUN npm run build 
EXPOSE 3000:80
CMD ["npm", "start"]

But so far have an issue with installing NodeJS in line with

RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

error: /bin/sh: 1: sudo: not found I was trying to install only the driver and for installing NodeJs just use some existing Docker images:

FROM ubuntu:16.04
USER root
RUN apt-get update
RUN apt-get install --yes curl
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get install -y build-essential
RUN apt-get install -y make
RUN apt-get install apt-transport-https
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql unixodbc-dev

FROM node:9-alpine
ADD . /var/www/app
WORKDIR /var/www/app
RUN npm install && \
    npm cache clean --force
RUN npm run build 
EXPOSE 3000:80

But that approach throws an error:

gyp ERR! configure error 
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:483:19)
gyp ERR! stack     at PythonFinder.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:397:16)
gyp ERR! stack     at F (/usr/local/lib/node_modules/npm/node_modules/which/which.js:68:16)
gyp ERR! stack     at E (/usr/local/lib/node_modules/npm/node_modules/which/which.js:80:29)
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/which/which.js:89:16
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/which/node_modules/isexe/index.js:42:5
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/which/node_modules/isexe/mode.js:8:5
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:170:21)
gyp ERR! System Linux 4.9.125-linuxkit
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /var/www/app/node_modules/odbc
gyp ERR! node -v v9.11.2
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok 
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp configure build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-03-08T20_51_17_496Z-debug.log
5
  • 1
    Why FROM ubuntu:16.04 and not something like FROM node:8? Not sure I fully understand your motivation for building your own Node image from scratch.
    – Max
    Commented Mar 8, 2019 at 21:05
  • I was trying that as well but then how can I install that MS ODBC driver? I need to use apt-get to install it. learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/…
    – camel
    Commented Mar 8, 2019 at 21:11
  • the official node docker image is based on Debian, so you can use apt-get as you want Commented Mar 8, 2019 at 21:23
  • so i should be able to use: FROM node:9-alpine RUN apt-get update RUN apt-get install --yes curl but getting /bin/sh: apt-get: not found
    – camel
    Commented Mar 8, 2019 at 21:28
  • ohh I need to either use FROM: node:10 to be able to use apt-get or node:10-alpine and then need to use apk instead of apt-get
    – camel
    Commented Mar 8, 2019 at 21:44

1 Answer 1

2

You are working off the ubuntu:16.04 image, and essentially doing a lot of footwork that the NodeJS guys have already done.

I would go for the image node:10-stretch-slim if I was you. And then install the drivers that you need with apt-get (if available, otherwise script the download and install in your Dockerfile).

The sudo command is not typically installed on docker images, because the user is root by default in the container sessions. If you see any errors concerning sudo, you can generally just remove sudo from the command line that is causing the issue.

Possible solution

Updating my answer here, with a possible solution for you.

This solution will put your application in a node 10 image, based on debian stretch 9. It will get the database drivers for you, from the debian 9 microsoft repository, and install all the packages that I see you are requiring from your question.

I have also added an ENTRYPOINT and CMD in the bottom of the script. But those lines are guesswork, since your question states nothing about how you actually start your application. (If you add that, then I will update my answer).

Note. Notice that I am passing --host 0.0.0.0 to the npm run start command. This is to avoid binding the live server to localhost, which will make in inaccessible from outside the container. Unless you start the container with --network="host".

You may have another means of starting your application that is more "production grade" than the live development server. If so, just replace the lines in the bottom of the Dockerfile, or ask me on this answer.

Dockerfile

# from debian stretch 9.8, node 10
FROM node:10-stretch-slim

# get apt-transport-https, etc., so that we can install by https protocol
RUN apt-get update \
 && apt-get install -y \
      apt-transport-https \
      build-essential \
      make

# add and accept the microsoft signature
RUN curl -q https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
# retrieve the microsoft packagelist for debian 9
RUN curl -q https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list

# install the ms odbc sql driver and unixodbc header stuff
RUN apt-get update \
 && ACCEPT_EULA=Y apt-get install -y \
      msodbcsql17 \
      unixodbc-dev \
 && rm -rf /var/lib/apt/lists

# expose port 80 in containers of this image
EXPOSE 80

# copy working directory into the image and set as pwd
ADD . /var/www/app
WORKDIR /var/www/app

# install dependencies for the application
RUN npm install \
 && npm cache clean --force

# build the application
RUN npm run build

# i am just guessing how you want your app started here, npm?
ENTRYPOINT ["npm"]
# and then this, which makes "npm run start --host 0.0.0.0"
CMD ["run", "start", "--host", "0.0.0.0"]

Build the image with:

docker build -t mynodeapp:0.1 .

Run the application image with:

docker run -p 3000:80 --name mynodeapp mynodeapp:01

Finally visit: http://localhost:3000 to see it working.

5
  • I am getting the long error W: The repository 'deb.debian.org/debian stretch Release' does not have a Release file. W: The repository 'security.debian.org/debian-security stretch/updates Release' does not have a Release file. W: The repository 'deb.debian.org/debian stretch-updates Release' does not have a Release file. E: Failed to fetch deb.debian.org/debian/dists/stretch/main/binary-amd64/Packages Error writing to output file - write (28: No space left on device) Error writing to file - write (28: No space left on device)
    – camel
    Commented Mar 9, 2019 at 21:23
  • That's odd - I just took the exact code from the Dockerfile in my answer and built it without any issues. And then I built it again with docker build --no-cache -t node:01 . - can you try copying the code again, and trying again? Commented Mar 9, 2019 at 22:06
  • The previous comment I solved. Can install all the stuff on the Docker but, still have issue with ODBC Driver: unixODBC][Driver Manager]Can\'t open lib \'/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.3.so.1.1\' : file not found but acctually it is installed: root@e1995a781ac6:/var/www/app# odbcinst -j unixODBC 2.3.7 DRIVERS............: /etc/odbcinst.ini SYSTEM DATA SOURCES: /etc/odbc.ini FILE DATA SOURCES..: /etc/ODBCDataSources USER DATA SOURCES..: /root/.odbc.ini SQLULEN Size.......: 8 SQLLEN Size........: 8 SQLSETPOSIROW Size.: 8
    – camel
    Commented Mar 9, 2019 at 22:12
  • Is this a new question? I don't think this this is related to the original question? Perhaps it is best explained in a new one. You can put some more data in there than you comment, and explain when it is happening? Commented Mar 9, 2019 at 23:14
  • Thank you for helping. I will open a new question regarding the ODBC Driver.
    – camel
    Commented Mar 10, 2019 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.