Docker(compose) installing nodejs broke npm - node.js

I need to use a container with nginx and nodejs, so I take the nginx container and install the node:
FROM nginx
ENV DEBIAN_FRONTEND noninteractive
WORKDIR /usr/src/app
VOLUME /usr/src/app
RUN apt-get update && \
apt-get install -y apt-utils && \
apt-get install -y --no-install-recommends curl sudo wget nano && \
curl -sL https://deb.nodesource.com/setup_6.x | bash - && \
apt-get install -y nodejs git build-essential && \
whereis npm && \
npm install grunt grunt-cli bower -g && \
whereis returnme nothing npm:, and npm install... crash the build proccess. so Where ir my mistake, is there a bug or anything? btw I'm using latest docker-compose and Docker version 17.03.1-ce, build c6d412e
Update 1: It is not a dupe of this question, I'm only using one RUN line

FROM nginx
RUN \
echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections && \
apt-get update && \
apt-get install -y apt-utils && \
apt-get upgrade -y && \
apt-get update --fix-missing && \
apt-get install -y curl sudo wget nano git build-essential
# Install NodeJS
RUN \
wget https://deb.nodesource.com/setup_6.x && \
chmod +x setup_6.x && \
./setup_6.x && \
apt-get install -y nodejs && \
npm install grunt grunt-cli

Related

Install postgresclient/sqlserver odbc drivers in dockerfile

I'm trying to install postgres odbc driver to connect with different external databases with pyodbc
My app receives credentials from any database of type mysql, sqlserver, postgresql, etc. And I'm having problems installing the drivers.
This is my docker file:
FROM python:3.10.9-bullseye
WORKDIR /code
ENV FLASK_APP app.py
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
RUN apt-get update
RUN apt-get install -y openjdk-17-jdk
#Mysql driver
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/debian/11/prod.list \
> /etc/apt/sources.list.d/mssql-release.list \
&& apt-get install -y --no-install-recommends \
locales \
apt-transport-https \
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& locale-gen \
&& apt-get update \
&& apt-get -y --no-install-recommends install unixodbc-dev libodbc1\
&& ACCEPT_EULA=Y apt-get -y --no-install-recommends install msodbcsql18
RUN sed -i -E 's/(CipherString\s*=\s*DEFAULT#SECLEVEL=)2/\11/' /etc/ssl/openssl.cnf
ENV ACCEPT_EULA=Y
RUN apt-get update -y && apt-get update \
&& apt-get install -y --no-install-recommends curl gcc g++ gnupg unixodbc-dev
#Postgresql
RUN apt-get update \
&& apt-get install -y libsasl2-modules-gssapi-mit libsasl2-modules
#Postgresql unicode
RUN apt-get install -y postgresql
RUN apt-get install -y odbc-postgresql
COPY . .
CMD ["flask", "run", "--debugger", "--reload", "--host=0.0.0.0"]
When I try to connecto with postgres database I got the error:
pyodbc.OperationalError: ('08001', '[08001] [unixODBC]could not
connect to server: No such file or directory\n\tIs the server running
locally and accepting\n\tconnections on Unix domain socket
"/var/run/postgresql/.s.PGSQL.5432"?\n (101) (SQLDriverConnect)')
When I connect with sql server database, I can extract info, but when I try to send info to the database I got this error:
TCP Provider: Error code 0x2746
I'm trying to set the openSSL to 1.0, and that allow me to extract info from sql servers database, but no send it with postgres, even the psql console is not installed :c
I'm having struggling with this drivers for some days. If anyone can help me, I'll be very greatful

Getting critical vulnerability after adding some modules to Dockerfile

`
FROM php:8.1-apache
RUN apt-get update
...
...
RUN docker-php-ext-install mysqli pdo_mysql && docker-php-ext-enable mysqli pdo_mysql
**RUN docker-php-ext-install exif && docker-php-ext-enable exif
RUN apt-get update && apt-get install -y libmagickwand-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
# install imagick
# Version is not officially released https://pecl.php.net/get/imagick but following works for PHP 8
RUN mkdir -p /usr/src/php/ext/imagick; \
curl -fsSL https://github.com/Imagick/imagick/archive/06116aa24b76edaf6b1693198f79e6c295eda8a9.tar.gz | tar xvz -C "/usr/src/php/ext/imagick" --strip 1; \
docker-php-ext-install imagick;
#install some base extensions
RUN apt-get update && apt-get install -y \
zlib1g-dev \
libzip-dev
RUN docker-php-ext-install zip
#gd
#RUN docker-php-ext-install gd && docker-php-ext-enable gd
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
&& docker-php-ext-install gd
#intl
RUN apt-get -y update \
&& apt-get install -y libicu-dev \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl**
RUN a2enmod rewrite
`
Once the docker image is build and push to ECR, I'm getting the 1 critical on Vulnerability part, this happens after adding the modules into the Dockerfile. Can anyone help me to reduce the size and which image to use.

Docker xvfb-run killed with ffmpeg

error:
xvfb-run: line 169: 18 Killed DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE
Dockerfile xvfb command
ENTRYPOINT ["/usr/bin/dumb-init", "--", "xvfb-run", "--server-args", "-screen 0 1280x1024x24 -ac"]
Full Dockerfile
FROM ubuntu:focal-20220302
WORKDIR /app
# Ensures tzinfo doesn't ask for region info.
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y \
dumb-init \
xvfb \
build-essential libxi-dev libglu1-mesa-dev libglew-dev pkg-config
# Source: https://gist.github.com/remarkablemark/aacf14c29b3f01d6900d13137b21db3a
# replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# update the repository sources list
# and install dependencies
RUN apt-get update \
&& apt-get install -y curl \
&& apt-get -y autoclean
RUN curl -fsSL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get install -y nodejs
# confirm installation
RUN node -v
RUN npm -v
# FONT CONFIG
RUN apt-get install fontconfig -y
## INSTALL EDITLY
# ## Install app dependencies
COPY package.json /app/
RUN npm install
# Add app source
COPY . /app
# Ensure `editly` binary available in container
RUN npm link
RUN apt-get update && apt-get install -y wget \
xz-utils \
dumb-init \
xvfb
# Get ffmpeg and ffprobe with static build
RUN wget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz \
&& tar xvf ffmpeg-release-amd64-static.tar.xz \
&& cp ffmpeg-5.0-amd64-static/ffmpeg /usr/local/bin/ \
&& cp ffmpeg-5.0-amd64-static/ffprobe /usr/local/bin/ \
&& rm -rf ffmpeg-release-amd64-static.tar.xz \
&& rm -rf ffmpeg-5.0-amd64-static
# Ensure ffmpeg and ffprobe are successfully copied
RUN ffmpeg -version && ffprobe -version
ENTRYPOINT ["/usr/bin/dumb-init", "--", "xvfb-run", "--server-args", "-screen 0 1280x1024x24 -ac"]
EXPOSE 3000
CMD [ "node","./index.js" ]

How to run pdfkit from_file in a Docker container

The following is my code for Docker:
FROM python:3.6.2-jessie
## Prepare apt-get:
RUN echo "debconf debconf/frontend select Noninteractive" | debconf-set-selections && \
apt-get update -qy && \
apt-get upgrade -qy && \
apt-get clean autoclean && \
apt-get install wkhtmltopdf -y && \
apt-get autoremove -y && \
apt-get install python3-setuptools -qy &&\
apt-get install python3-dev -qy && \
apt-get install python3-pip -qy && \
apt-get install build-essential -qy && \
apt-get -y install openssh-client -qy && \
apt-get clean
RUN pip3 install --upgrade pip
RUN pip3 install pandas
RUN pip3 install psycopg2==2.7.3.2
RUN pip3 install pdfkit
When I run following code,
docker run my_image python3 pdfkit.py
I get the following error:
OSError: wkhtmltopdf exited with non-zero code -6. error: The switch
--viewport-size, is not support using unpatched qt, and will be ignored.The switch --disable-smart-shrinking, is not support using
unpatched qt, and will be ignored.QXcbConnection: Could not connect to
display
Try the following:
RUN curl -L#o wk.tar.xz https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz \
&& tar xf wk.tar.xz \
&& cp wkhtmltox/bin/wkhtmltopdf /usr/bin \
&& cp wkhtmltox/bin/wkhtmltoimage /usr/bin \
&& rm wk.tar.xz \
&& rm -r wkhtmltox
Rather than installing directly using apt-get install wkhtmltopdf -y.

Create a nodejs container Docker based on ubuntu

I used the official nodejs image to create a docker container that run a nodejs app.
But now I want to create the same docker but my own base on ubuntu:14.04 but it doesn't work
Dockerfile mynode
FROM ubuntu:14.04
RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get install nodejs -y
RUN apt-get install nodejs-legacy -y
RUN apt-get install npm -y
RUN npm install -g nodemon
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY ./prj/package.json /usr/src/app/
RUN npm install
ADD ./prj /usr/src/app
EXPOSE 9977
# Run app using nodemon
CMD ["nodemon", "/usr/src/app/app.js"]
If I change the line from ubuntu:14.04 to node it works well.
But now if I use a docker-compose to build and run the container it doesn't work.
node:
restart: always
build: ./mynodeFolder
ports:
- "9977:9977"
I have the error :
Now if I use the image build with the mynode DockerFile and use docker run -it --rm myNewContainer bash and then start my app using nodemon it works perfectly !
So everything is well installed and packed within the my dockerimage, so why it doesn't work when build with the docker-compose
It works now when i use this DockerFile
# Set the base image to Ubuntu
FROM ubuntu:14.04
#FOR DEBUGGING
RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get install nodejs -y
RUN apt-get install nodejs-legacy -y
RUN apt-get install npm -y
# Install nodemon
RUN npm install -g nodemon
# Provides cached layer for node_modules
RUN mkdir -p /usr/src/app
# Define working directory
WORKDIR /usr/src/app
ADD ./prj /usr/src/app
RUN npm install
# Expose port
EXPOSE 9977
# Run app using nodemon
CMD ["nodemon", "/usr/src/app/app.js"]
Here is the Dockerfile for the official node image:
https://github.com/nodejs/docker-node/blob/5d433ece4d221fac7e38efbec25ffea2dea56286/5.2/Dockerfile
RUN set -ex && for key in 9554F04D7259F04124DE6B476D5A82AC7E37093B 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 FD3A5288F042B6850C66B31F09FE44734EB7990E 71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 DD8F2338BAE7501E3DD5AC78C273792F7D83545D ; do gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; done
ENV NPM_CONFIG_LOGLEVEL=info
ENV NODE_VERSION=5.2.0
RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz" && curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" && gpg --verify SHASUMS256.txt.asc && grep " node-v$NODE_VERSION-linux-x64.tar.gz\$" SHASUMS256.txt.asc | sha256sum -c - && tar -xzf "node-v$NODE_VERSION-linux-x64.tar.gz" -C /usr/local --strip-components=1 && rm "node-v$NODE_VERSION-linux-x64.tar.gz" SHASUMS256.txt.asc
CMD "node"
If you go to http://imagelayers.io, you can see the combined Dockerfile for the image, including the buildpack-deps:jessie base image:
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl wget && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y --no-install-recommends bzr git mercurial openssh-client subversion procps && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y --no-install-recommends autoconf automake bzip2 file g++ gcc imagemagick libbz2-dev libc6-dev libcurl4-openssl-dev libevent-dev libffi-dev libgeoip-dev libglib2.0-dev libjpeg-dev liblzma-dev libmagickcore-dev libmagickwand-dev libmysqlclient-dev libncurses-dev libpng-dev libpq-dev libreadline-dev libsqlite3-dev libssl-dev libtool libwebp-dev libxml2-dev libxslt-dev libyaml-dev make patch xz-utils zlib1g-dev && rm -rf /var/lib/apt/lists/*
RUN set -ex && for key in 9554F04D7259F04124DE6B476D5A82AC7E37093B 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 FD3A5288F042B6850C66B31F09FE44734EB7990E 71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 DD8F2338BAE7501E3DD5AC78C273792F7D83545D ; do gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; done
ENV NPM_CONFIG_LOGLEVEL=info
ENV NODE_VERSION=5.2.0
RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz" && curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" && gpg --verify SHASUMS256.txt.asc && grep " node-v$NODE_VERSION-linux-x64.tar.gz\$" SHASUMS256.txt.asc | sha256sum -c - && tar -xzf "node-v$NODE_VERSION-linux-x64.tar.gz" -C /usr/local --strip-components=1 && rm "node-v$NODE_VERSION-linux-x64.tar.gz" SHASUMS256.txt.asc
CMD "node"

Resources