Upgrade or install Ghostscript 9.21 in docker image node:7 - node.js

I'm installing Ghostscript into a docker image and want to use it with ghostscript4js which requires for some functionality at least Ghostscript 9.21.
I'm using this in my docker file which installs Ghostscript 9.06
FROM node:7
ARG JOB_TOKEN
RUN apt-get update && \
apt-get install -y pdftk
ENV APP_DIR="/usr/src/app" \
JOB_TOKEN=${JOB_TOKEN} \
APP_DIR="/usr/src/app" \
GS4JS_HOME="/usr/lib"
COPY ./ ${APP_DIR}
# Step 1: Install App
# -------------------
WORKDIR ${APP_DIR}
# Step 2: Install Python, GhostScript and npm packages
# -------------------
ARG CACHE_DATE=2017-01-01
RUN \
apt-get update && \
apt-get install -y build-essential make gcc g++ python python-dev python-pip python-virtualenv && \
apt-get -y install ghostscript && apt-get clean && \
apt-get install -y libgs-dev && \
rm -rf /var/lib/apt/lists/*
RUN npm install
# Step 3: Start App
# -----------------
CMD ["npm", "run", "start"]
How do I install or upgrade to a higher Ghostscript version in a docker image?

Seems like the distro you are using (since you use apt-get) is only on 9.06. Not surprising, many distros remain behind the curve, especially long term support ones.
If you want to use a more recent version of Ghostscript, then you could nag the packager to update. And you know, 9.06 is 5 years old now.....
Failing that you'll have to build it yourself. Git clone the Ghostscript repository, cd ghostpdl, ./autogen.sh, make install. That of course gets the current bleeding edge source, for a release version you'll have to pull from one of the tags (we tag the source for each release).
Or build it yourself locally and put it somewhere that your docker image can retrieve it from.
IMO if you are going to use a version other than the one provided by the packager of your distro, you may as well use the current release. That's currently 9.22 and will be 9.23 in a few weeks.

Related

Dockerfile for Python3 and OpenCV

I need to have a Dockerfile with Python3 and the latest version of OpenCV. The Dockerfile I have written is described below:
FROM ubuntu
#Install OpenCV
RUN apt-get update &&\
apt-get install -y cmake
RUN apt-get install -y gcc g++
RUN apt-get install -y python3-dev python3-numpy
# To support GUI features
RUN apt-get install -y libavcodec-dev libavformat-dev libswscale-dev
# To support GTK 2
RUN apt-get install -y libgtk2.0-dev
# To support GTK 3
RUN apt-get install -y libgtk-3-dev
#Optional dependencies
RUN apt-get install -y libpng-dev
RUN apt-get install -y libjpeg-dev
RUN apt-get install -y libopenexr-dev
RUN apt-get install -y libtiff-dev
RUN apt-get install -y libwebp-dev
# Clone OpenCV repo
RUN apt-get install -y git
RUN git clone https://github.com/opencv/opencv.git
#Compile
RUN mkdir /opencv/build && \
cd /opencv/build
RUN cmake ..
RUN make
However, when i run it, it gives me the following error with cmake.
Step 17/27 : RUN cmake ..
---> Running in 3dca32df2036
CMake Error: The source directory "/" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
The command '/bin/sh -c cmake ..' returned a non-zero code: 1
Do you know what am i doing wrong?
You just need to chain the last RUN instructions:
#Compile
RUN mkdir /opencv/build && \
cd /opencv/build && \
cmake .. && \
make
Explanation:
A RUN statement creates a new image layer and executes the specified shell command. This means that each RUN statement will run the command in a separate shell, so the current directory from the previous RUN will not be preserved (you can see that the CMake current directory is / by looking closely at the error message).
You can find more info about RUN statement in the Docker documentation and I also recommend reading Best practices for writing Dockerfiles.

Azure: How to create an environment where the VM has a special package installed?

I am about to deploy a model on Azure but the model needs a special package installed on Ubuntu. My model is written in python and I have a python-wrapper installed (and other necessary pip packages) already in the environment.
The challenge is that the wrapper needs the special package to be installed on the Ubuntu. How and at what point I need to specify what packages I want to be installed on Ubuntu when creating the environment? The package is not a default one.
The following code snippet helped me to solve this. Just substitute the package you want to install into "<'package-1'>".
FROM <prebuilt docker image from MCR>
# Switch to root to install apt packages
USER root:root
RUN apt-get update && \
apt-get install -y \
**<package-1>** \
...
<package-n> && \
apt-get clean -y && \
rm -rf /var/lib/apt/lists/*
# Switch back to non-root user
USER dockeruser
The complete tutorial can be found here: https://learn.microsoft.com/en-us/azure/machine-learning/how-to-extend-prebuilt-docker-image-inference

apk not found error while changing to node-buster from Alpine base image

I have changed my image in docker from Alpine base image to node:14.16-buster, While running the code I am getting 'apk not found' error.
Sharing the codes snippet :
FROM node:14.16-buster
# ========= steps for Oracle instant client installation (start) ===============
RUN apk --no-cache add libaio libnsl libc6-compat curl && \
cd /tmp && \
curl -o instantclient-basiclite.zip https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip -SL && \
unzip instantclient-basiclite.zip && \
mv instantclient*/ /usr/lib/instantclient && \
rm instantclient-basiclite.zip
Can you please help here, what do I need to change?
The issue comes from the fact that you're changing your base image from Alpine based to Debian based.
Debian based Linux distributions use apt as their package manager (Alpine uses apk).
That is the reason why you get apk not found. Use apt install, but also keep in mind that the package names could differ and you might need to look that up. After all, apt is a different piece of software with it's own capabilities.
Buster images are based on the Debian version.
It doesn't support the APK default package manger is APT
For example you can do :
FROM node:15.14.0-buster-slim
RUN apt-get update && \
apt-get install -y \
curl \
jq \
git \
wget \
openssl \
bash \
tar \
net-tools && \
rm -rf /var/lib/apt/lists/*
RUN mkdir /app && \
chown node:node /app
APK is part of the Linux alpine version you have to change the base version if you want to use the APK.
The buster node images are Debian based. buster is the release name for Debian 10 (11 will be bullseye).
Debian uses APT for packaging. apt-get can be used from scripts
apt-get update && apt-get install libaio1 curl
libnsl2 is not available in Buster, but you might not need it

How to refresh your shell when using a Dockerfile?

I am trying to build a Dockerfile that can make use of Azure functions. After unsuccessfully trying to build it using alpine:3.9 because of library issues, I swapped to ubuntu:18.04. Now I have a problem in that I can't install nvm (node version manager) in such a way that I can install node. My Dockerfile is below. I have managed to install nvm but now, while trying to use nvm, I cannot install the node version I want. The problem probably has to do with refreshing the shell but that is tricky to do as it appears that Docker continues to use the original shell it entered to run the next build stages. Any suggestions on how to refresh the shell so nvm can work effectively?
FROM ubuntu:18.04
RUN apt update && apt upgrade -y && apt install -qq -y --no-install-recommends \
python-pip \
python-setuptools \
wget \
build-essential \
libssl-dev
RUN pip install azure-cli
RUN wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
RUN . /root/.nvm/nvm.sh && nvm install 10.14.1 && node
ENTRYPOINT ["/bin/bash"]
After install nvm command put:
SHELL ["/bin/bash", "--login" , "-c"]
RUN nvm install 17
SHELL ["/bin/sh", "-c"]
Default shell is sh and first command switches it to bash. Parameter --login is required as you want to source .bashrc.
As all subsequent commands would be executed with changed shell it's good to switch it back to sh if you don't need it anymore.
You usually don't need version managers like nvm in a Docker image. Since a Docker image packages only a single application, and since it has its own isolated filesystem, you can just install the single version of Node you need.
The first thing I'd try is to just install whatever version of Node the standard Ubuntu package has (in Ubuntu 18.04, looks like 8.11). While there are some changes between Node versions, for the most part the language and core library have been pretty stable.
RUN apt update && apt-install nodejs
Or, if you need something newer, there are official Debian packages:
RUN curl -sSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - \
&& echo "deb https://deb.nodesource.com/node_10.x cosmic main" > /etc/apt/sources.list.d/nodesource.list \
&& apt update \
&& apt install nodejs
This will give you a current version of that major version of Node (as of this writing, 10.15.1).
If you really need that specific version of Node, there are official binary packages. I might write:
FROM ubuntu:18.04
ARG node_version=10.14.1
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --assume-yes \
ca-certificates \
curl \
xz-utils
RUN cd /usr/local \
&& curl -o- https://nodejs.org/dist/v${node_version}/node-v${node_version}-linux-x64.tar.xz \
| tar xJf - --strip 1
...where the last couple of lines unpack the Node tarball directly into /usr/local.

update git version in docker container

I am implementing a node.js application in docker, that needs to make use of the git worktree feature. However, even if I do :
RUN apt-get update && apt-get install -y git=2.10.0
it can't find any other version after 2.1.0
I am building the image from :
FROM node:4.4.2
How can I get the latest git version that supports the worktree feature installed on a docker container
As of the time of this post, no package repos from Debian include a version beyond 2.9. If you need a newer version, you'll need to download and install that from source which is documented on git-scm, or find another repo.
From some other answers (credit to #Alex Karshin), this solution works for me in the Dockerfile
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y git
See https://askubuntu.com/a/568596/159234
RUN apt-add-repository ppa:git-core/ppa && apt-get update && apt-get install -y git

Resources