I'm trying to create a dockerfile for my Node application that uses Selenium WebDriver. I tried the code below, it creates a directory for node, install geckodriver and firefox.
FROM node:12
WORKDIR /usr/app
COPY package*.json ./
RUN npm install
# Install geckodriver
RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz
RUN tar -xvzf geckodriver-v0.24.0-linux64.tar.gz
RUN chmod +x geckodriver
RUN mv geckodriver /usr/local/bin/
# Install firefox
RUN wget "https://download.mozilla.org/?product=firefox-latest&os=linux&lang=pt-BR" -O firefox.tar.bz2
RUN tar -jxvf firefox.tar.bz2 -C /usr/local/bin/
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
The error I receive is SessionNotCreatedError: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line. So, the geckodriver doesn't find the firefox binary. I guess isn't setting the firefox well in PATH system, I try to call firefox --version and not found.
The index.js only do:
const { Builder } = require('selenium-webdriver');
const driver = await new Builder().forBrowser('firefox').build();
await driver.get('https://google.com');
I solve the problem with this dockerfile:
FROM ubuntu
RUN apt-get update
RUN apt install nodejs -y
RUN apt install npm -y
RUN node -v
WORKDIR /usr/app
COPY package*.json ./
RUN npm install
RUN apt install wget -y
RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.29.0/geckodriver-v0.29.0-linux64.tar.gz
RUN tar -xvzf geckodriver-v0.29.0-linux64.tar.gz
RUN chmod +x geckodriver
RUN mv geckodriver /usr/local/bin/
RUN apt install firefox -y
RUN export MOZ_HEADLESS=1
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
I've changed the firefox installation way and added export MOZ_HEADLESS=1
Related
our app is nodejs based and needs to query Oracle DB, so we install NPM oracledb package. So our Docker image is based on oracle instant client, the Docker file looks like following:
FROM frolvlad/alpine-glibc
RUN apk update && apk add libaio
COPY instantclient_12_1.zip ./
RUN unzip instantclient_12_1.zip
RUN mv instantclient_12_1/ /usr/lib/
RUN rm instantclient_12_1.zip
RUN ln /usr/lib/instantclient_12_1/libclntsh.so.12.1 /usr/lib/libclntsh.so
RUN ln /usr/lib/instantclient_12_1/libocci.so.12.1 /usr/lib/libocci.so
RUN ln /usr/lib/instantclient_12_1/libociei.so /usr/lib/libociei.so
RUN ln /usr/lib/instantclient_12_1/libnnz12.so /usr/lib/libnnz12.so
ENV ORACLE_BASE /usr/lib/instantclient_12_1
ENV LD_LIBRARY_PATH /usr/lib/instantclient_12_1
ENV TNS_ADMIN /usr/lib/instantclient_12_1
ENV ORACLE_HOME /usr/lib/instantclient_12_1
RUN apk add nodejs npm
RUN mkdir -p /var/app
WORKDIR /var/app
ADD package.json /var/app
COPY . /var/app
CMD ["npm","start"]
But when our app starts using 'oracledb' NPM package, it got following error:
init() error: DPI-1047: Cannot locate a 64-bit Oracle Client library: "Error loading shared library libnsl.so.1: No such file or directory (needed by /usr/lib/libclntsh.so)". See https://oracle.github.io/odpi/doc/installation.html#linux for help Node-oracledb installation instructions: https://oracle.github.io/node-oracledb/INSTALL.html
You must have 64-bit Oracle client libraries in LD_LIBRARY_PATH, or configured with ldconfig.
If you do not have Oracle Database on this computer, then install the Instant Client Basic or Basic Light package from http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
So Oracle client couldn't find libnsl.so.1 even thought it should come with glibc, and I can see that it is under:
'/usr/glibc-compat/lib'.
Any ideas how to fix this? Thanks in Advance.
# 1. Install dependencies
FROM node:8.15 as cache-package
COPY package.json /srv/src/package.json
WORKDIR /srv/src
RUN yarn install
# 2.
FROM node:8.15 as builder
# 1. Update everything on the box
RUN apt-get update && \
apt-get install sudo
#RUN apk --update add libaio bc net-tools
RUN sudo apt-get install unzip
RUN sudo apt-get install wget
RUN sudo apt-get install git
# 3. Install oracle client
RUN mkdir -p /opt/oracle
# 3.1 Get oracle client
WORKDIR /opt/oracle
RUN wget -O /opt/oracle/instantclient_18_3_linux.zip http://YOUR_URL_TO_DOWNLOAD_THE_CLIENT/instantclient_18_3_linux.zip
RUN sudo unzip /opt/oracle/instantclient_18_3_linux.zip
# 3.2 Configure oracle client to work with node
RUN sudo sh -c "echo /opt/oracle/instantclient_18_3_linux > /etc/ld.so.conf.d/oracle-instantclient.conf"
RUN sudo cat /etc/ld.so.conf.d/oracle-instantclient.conf
FROM node:8.15
RUN apt-get update && \
apt-get install sudo
RUN sudo apt-get install libaio1
RUN mkdir -p /srv/src/logs
RUN mkdir -p /srv/logs
RUN mkdir -p /opt/oracle
# 4. Set the working directory
# 5. Copy our project & install our dependencies
COPY --from=cache-package /srv/src /srv/src
COPY --from=builder /opt/oracle/instantclient_18_3_linux /opt/oracle/instantclient_18_3_linux
COPY --from=builder /etc/ld.so.conf.d/oracle-instantclient.conf /etc/ld.so.conf.d/oracle-instantclient.conf
RUN sudo ldconfig
RUN ln -sf /usr/share/zoneinfo/WET /etc/localtime
COPY . /srv/src
WORKDIR /srv/src
# 6. Start the app
CMD yarn start
Here is my dockerfile working fine, the srv/src is my directory where I have my code, just change for yours and it should work.
I have the same problem as you the past two days and now it works.
WE have a node.js web app.We have deployed it on server with docker.
Its working fine with node version 0.10.25. But right now i have decided it to run on latest version of node 6.5.0
To accomplish this i modified the docker file which is now looking like below
FROM ubuntu:14.04
RUN echo 'deb http://security.ubuntu.com/ubuntu trusty-security main' | sudo tee -a /etc/apt/sources.list
RUN sudo apt-get update
RUN sudo apt-get install linux-libc-dev curl git-core krb5-multidev libkrb5-dev -y
RUN sudo curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
RUN sudo apt-get install nodejs -y
RUN sudo ln -sf /usr/bin/nodejs /usr/bin/node
RUN ["/bin/bash", "-c", "node -v"]
RUN sudo npm cache clean
RUN sudo npm install -g bower -y
RUN sudo npm install -g gulp -y
#RUN sudo npm install -g node-sass
#RUN sudo npm install -g eslint -y
#RUN sudo npm install -g htmllint -y
RUN cd /root; git clone -b masterclone https://consultancy:Admin23#github.com/newapp/web.git
RUN cd /root/web; sudo npm install; sudo bower install --allow-root; gulp clean-build-app-prod
EXPOSE 8000
CMD cd /root/web; NODE_ENV=production node server.js
Everything went fine except the below line which i guess causing the problem
"The command '/bin/sh -c cd /root/web; sudo npm install; sudo bower install --allow-root; gulp clean-build-app-prod' returned a non-zero code: 1"
Use the official node image. Here a example file.
FROM node:6.5
# Enviroment variables
ENV NPM_CONFIG_LOGLEVEL warn
ENV USER node
ENV HOMEDIR /data
# add user node and change dir working dir
RUN useradd -ms /bin/bash ${USER}
RUN mkdir -p ${HOMEDIR}
WORKDIR ${HOMEDIR}
# install all dependencies
COPY package.json ./
RUN npm install --production
# add node content
COPY . .
USER node
EXPOSE 8000
CMD ["npm", "start"]
It's probably simpler to base your file off of the official NodeJS image. For v6.5, that means that FROM ubuntu:14.04 becomes FROM node:6.5.
Also, instead of doing RUN cd /root/web over and over, you might want to change the working directory with WORKDIR /root/web.
I'm trying to get Whois working in NodeJS on a Dockerfile. I'm using Whois-UX (which just spawns a whois process with the whois linux command. I'm using the "node:argon" docker image, but it doesn't have whois installed. There doesn't seem to be a way to apt-get install whois inside the image either.
I then tried to use "ubuntu:12.04", but I'm having trouble running the app with it. Here is my Dockerfile:
FROM ubuntu:12.04
WORKDIR /srv
ADD . /srv
RUN apt-get update
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup | bash -
RUN apt-get install -y nodejs git git-core whois
RUN npm install
CMD ["node /srv/server.js"]
So, there are two possible solutions that I don't know how to solve. Figure out how to get whois on the node:argon image, or get the ubuntu docker image to work. I'd rather get whois on node:argon, because of optimizations for NodeJS, but as long as it works, it'll do.
Thanks for the help!
Whelp. I got it.
I forgot to apt-get update before I apt-get installed whois, so it didn't show the repository as being up.
FROM node:argon
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN apt-get update
RUN apt-get install whois
RUN npm install bower -g
COPY package.json /usr/src/app/
RUN npm install
COPY . /usr/src/app
RUN bower install --allow-root
CMD ["npm", "start"]
^ This worked.
I'm trying to use docker with my node application, my Dockerfile looks like this:
RUN apt-get update
RUN apt-get -y install build-essential
RUN apt-get install -y nodejs
RUN apt-get install -y npm
ADD . /src
RUN cd /src && npm install
EXPOSE 8080
CMD ["node","/src/app.js"]
but after running docker build when npm install is running after trying to install https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz I get an error:
The command 'bin/sh -c /src && npm install' returned a non-zero code : 1
What can cause such an issue? I've already tried to install node-legacy instead of node and it didn't work
Try this:
# put this line on your code (if you are using ubuntu)
# this make a link from nodejs to node to add compatibility on ubuntu OS
RUN ln -s /usr/bin/nodejs /usr/bin/node
# set your current directory with WORKDIR
WORKDIR /src
RUN sudo npm install
This is the complete dockerfile
FROM ubuntu:12.04
# Create directory
RUN mkdir -p /dir/subdir
# Download wget
RUN apt-get install -y wget
# Make sure package is up to date
RUN apt-get update
# Install nodejs
WORKDIR /dir
RUN wget http://nodejs.org/dist/v0.10.26/node-v0.10.26-linux-x64.tar.gz
RUN tar -zxf node-v0.10.26-linux-x64.tar.gz
RUN cd /node-v0.10.26-linux-x64 && ./configure
RUN cd /node-v0.10.26-linux-x64 && make
RUN cd /node-v0.10.26-linux-x64 && make install
# Update again
RUN apt-get-update
# Copy all the files
ADD dir/subdir dir/subdir
EXPOSE 8080
CMD ["node", "/dir/subdir/index.js"]
This is part of the log where it gets an error
Step 6 : RUN tar -zxf node-v0.10.26-linux-x64.tar.gz
---> Running in xxxxxxx
---> xxxxxxxxxxxxxx
Removing intermediate container xxxxxxxxxxxx
Step 7 : RUN cd /node-v0.10.26-linux-x64 && ./configure
---> Running in xxxxxxxx
[91m/bin/sh: 1: cd: can't cd to /node-v0.10.26-linux-x64
[0m
The command [/bin/sh -c cd /node-v0.10.26-linux-x64 && ./configure] returned a non-zero code: 2
Does anyone know what the error 2 means and how to fix it?
This time I tested it.
FROM ubuntu:12.04
# Create directory
RUN mkdir -p /dir/subdir
# Make sure package is up to date
RUN apt-get update
# Install dependencies
RUN apt-get install -y build-essential openssl libssl-dev pkg-config python
# Install nodejs
WORKDIR /dir
ADD http://nodejs.org/dist/v0.10.29/node-v0.10.29.tar.gz /dir/
RUN tar -zxf node-v0.10.29.tar.gz
WORKDIR /dir/node-v0.10.29
RUN ./configure && make && make install
WORKDIR /dir
# Copy all the files
ADD dir/subdir dir/subdir
EXPOSE 8080
CMD ["node", "/dir/subdir/index.js"]
Docker (v1.0.0) will use WORKDIR for subsequent RUN. cd /node-v0.10.26-linux-x64 won't work as the untar occured in /dir.