Install RPM package in a pre-built node image - docker

I am writing a Node app I want to containerize using a pre-built node image (https://hub.docker.com/_/node/). I need to deploy application that I only have a RPM package for and I cannot figure out where to start finding documentation or a small example to do this.
The examples I'm looking at use yum, which I don't have (from my understanding) in the pre-built node image.
COPY src/MyApp/lib/3rdPartyApp.x86_64.rpm ./3rdPartyApp.x86_64.rpm
RUN yum localinstall 3rdPartyApp.x86_64.rpm; yum clean all && \
rm ./3rdPartyApp.x86_64.rpm
My other option is to use a CentOS docker image which has yum. But I'm running in to problems getting Node installed there trying to use NVM. But I'm also reading I shouldn't try to use NVM when building a Docker container and there is a better way.

You can use alien to convert packages from one format to another.
FROM node
RUN apt-get update && apt-get install -y alien
COPY src/MyApp/lib/3rdPartyApp.x86_64.rpm ./3rdPartyApp.x86_64.rpm
RUN alien -d -i 3rdPartyApp.x86_64.rpm
This will leave a lot of extra files in your image. You can use two step build to clear it up.
FROM node AS builder
RUN apt-get update && apt-get install -y alien
COPY src/MyApp/lib/3rdPartyApp.x86_64.rpm ./3rdPartyApp.x86_64.rpm
RUN alien -d 3rdPartyApp.x86_64.rpm
FROM node
COPY --from=builder 3rdPartyApp.x86_64.deb .
RUN dpkg -i 3rdPartyApp.x86_64.deb && rm 3rdPartyApp.x86_64.deb

FROM centos:centos7.6.1810
# Enable EPEL to install Node.js and npm
RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm && \
    yum -y update && \
    yum install -y npm git && \
    yum clean all

Related

Can't install hadoop in a dockerfile which has ubuntu as base image

When I run the following code, I get this error, E: Unable to locate package hadoop
FROM ubuntu:20.04
RUN apt-get update -y \
&& apt-get install -y apt-utils \
&& apt-get install python3.8 -y
RUN apt-get install jupyter -y
RUN apt-get install hadoop -y
RUN rm -rf /var/lib/apt/lists/*
ADD sample.py /
LABEL maintainer=Ammar
CMD [ "python", "./sample.py" ]
This link: https://computingforgeeks.com/install-apache-hadoop-hbase-on-ubuntu-linux/ contains full example of Hadoop installation. I think the same should be done in Docker step-by-step.
apt-get install hadoop not working in ubuntu without adding external repositories. But if you know external repo, then you must add softwaree-properties-common package (like this: https://stackoverflow.com/a/52091668/1852444)
and then add your repository by apt-add-repository command.
Some "foss" softwares and Softwares which do not comes under foss are not added in ubuntu repository so they cannot be install using apt because apt use these repositories to install package.
hadoop is one of these packages which is not added to ubuntu repo. For more info about repository you can check here
You can pull and use one of the hadoop container image created and pushed in dockerhub by others instead of creating it for scratch.
If you still want to create your own hadoop container image you can check out this example hadoop dockerfile

issue in creating docker image from docker file

Created a Docker file in oreder to install Tomcat server from Unix as bashe os
My Dockerfile:
FROM ubuntu
RUN apt-get update && apt-get upgrade -y #to update os
RUN apt-get dist-upgrade
RUN apt-get install build-essential
RUN apt-get install openjdk-8-jdk # to install java 8
RUN apt-get wget -y #to install wget package
RUN apt-get wget https://mirrors.estointernet.in/apache/tomcat/tomcat-9/v9.0.37/bin/apache-tomcat-9.0.37.tar.gz #to download tomcat
RUN tar -xvzf apache-tomcat-9.0.37 # unzipping the tomcat
RUN mkdir tomcat # craeting tomacat directory
RUN cp apache-tomcat-9.0.37/* tomcat # copying tomact files to tomact directory
Command to create Docker Image from Docker file:
docker build -t [img name] -f [file name] .
On execution, while installing java package am getting like this:
'''After this operation, 242 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y'''
You are getting the prompt because the command is awaiting user input for whether or not to install a package. The -y flag you're using for a few of them (like wget) allows bash to assume a yes. Add this flag to all your installation commands.
By the way, there's quite a few potential issues with the Dockerfile you posted.
For example, you have RUN apt-get wget ...
Are you sure that is what you want to do, and not just RUN wget ...? Unless wget is a command that apt-get takes, which it isn't, it will cause unexpected behavior.
You also seem to be missing the command to start the Tomcat server, which can make it so that nothing happens when you attempt to run the image.
I think you should add DEBIAN_FRONTEND=noninteractive when running the apt-get commands, something like this:
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install build-essential -y
Also, it's considered bad practice to use multiple RUN steps which could be consolidated into one. More about Dockerfile best practices can be found here.

Install Java runtime in Debian based docker image

I am trying to install the java runtime in a Debian based docker image (mcr.microsoft.com/dotnet/core/sdk:3.1-buster). According to various howtos this should be possible by running
RUN apt update
RUN apt-get install openjdk-11-jre
The latter command comes back with
E: Unable to locate package openjdk-11-jre
However according to https://packages.debian.org/buster/openjdk-11-jre the package does exist. What am I doing wrong?
Unsure from which image your are pulling. I used slim, Dockerfile.
from debian:buster-slim
ENV DEBIAN_FRONTEND=noninteractive
RUN mkdir -p /usr/share/man/man1 /usr/share/man/man2
RUN apt-get update && \
apt-get install -y --no-install-recommends \
openjdk-11-jre
# Prints installed java version, just for checking
RUN java --version
NOTE: If you don't run the mkdir -p /usr/share/man/man1 /usr/share/man/man2 you'll run into dependency problems with ca-certificates, openjdk-11-jre-headless etc. I've been using this fix provided by community, haven't really checked the permanent fix.

How to create the smallest possible Docker image after installing apt dependencies

I've created a Docker image using debian as the parent image. In my Dockerfile I've installed some dependencies using apt and pip.
Now, I want to get rid off everything that is not completely necessary to run my app, which of course, needs the dependencies installed.
For now I have the following lines in my Dockerfile after installing the dependencies.
RUN rm -rf /var/lib/apt/lists/* \
&& rm -Rf /usr/share/doc && rm -Rf /usr/share/man \
&& apt-get clean
I've also installed the dependencies using the --no-install-recommends option.
Anything else I can do to reduce the footprint of my Docker image?
PS: just in case, this is how I installed the dependencies:
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
sudo systemd \
build-essential libffi-dev libssl-dev \
python-pip python-dev python-setuptools python-wheel
To reduce the size of the image, you need to combine your RUN commands into one. When you create files in one layer and delete them in another, the files still exist on the drive and are shipped over the network. Their existence is just hidden when the layers of the filesystem are assembled for your container.
The Dockerfile best practices explain this in more detail: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run
I'd also recommend building with docker build --rm=false --no-cache . (temporarily) and then reviewing the output of docker diff on each of the created images to see what files are created in each layer.

Docker commands require keyboard interaction

I'm trying to create a Docker image for ripping CDs (using abcde).
Here's the relevant portion of the Dockerfile:
FROM ubuntu:17.10
MAINTAINER Graham Nicholls <graham#rockcons.co.uk>
RUN apt update && apt -y install eject vim ruby abcde
...
Unfortunately, the package "abcde" pulls in a mail client (not sure which), and apt tries to configure that by asking what type of mail connection to configure (smarthost/relay etc).
When docker runs, it's not appearing to read from stdin, so I can't redirect into the docker process.
I've tried using --nodeps with apt (and replacing apt with apt-get); unfortunately --nodeps seems no-longer to be a supported option and returns:
E: Command line option --nodeps is not understood in combination with the other options
Someone has suggested using expect in response to a similar question, which I'd rather avoid. This seems to be a "difficult to google" problem - I can't find anything.
So, is there a way of passing in the answer to the config in apt, or of preventing apt from pulling in a mail client, which would be better - I'm not planning in sending updates to cddb.
The typical template to install apt packages in a docker container looks like:
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
eject \
vim \
ruby \
abcde \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
Running it with the "noninteractive" value removes any prompts. You don't want to set that as an ENV since that would also impact any interactive commands you run inside the container.
You also want to cleanup the package database when finished to reduce the layer size and avoid reusing a stale cached package database in a later step.
The no-install-recommends option will reduce the number of packages installed by only installing the required dependencies, not the additional recommended packages. This cuts the size of the root filesystem down by half for me.
If you need to pass a non-default configuration to a package, then use debconf. First run you install somewhere interactively and enter the options you want to save. Install debconf-utils. Then run:
debconf-get-selections | grep "${package_name}"
to view all the options you configured for that package. You can then pipe these options to debconf-set-selections in your container before running your install, e.g.:
RUN echo "postfix postfix/main_mailer_type select No configuration" \
| debconf-set-selections \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
....
or save your selections to a file that you copy in:
COPY debconf-selections /
RUN debconf-set-selections </debconf-selections \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
....

Resources