optimise multiple execution of same command - Docker - postgresql

I am trying to install and configure postgresql-client-11 on my ubuntu18:04. I understand that we need to perform a few extra steps shown below to do the same (Source: https://www.itzgeek.com/how-tos/linux/ubuntu-how-tos/how-to-install-postgresql-10-on-ubuntu-18-04-lts.html)
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O- | sudo apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" | sudo tee /etc/apt/sources.list.d/postgresql.list
sudo apt-get update
sudo apt-get install -y postgresql-client-11
I am achieving it with the following
RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y wget && apt-get install -y gnupg2
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" | tee /etc/apt/sources.list.d/postgresql.list
RUN wget https://www.postgresql.org/media/keys/ACCC4CF8.asc
RUN apt-key add ACCC4CF8.asc
RUN apt-get update && apt-get dist-upgrade -y && DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs && rm -rf /var/lib/apt/lists/*
I am executing the same command RUN apt-get update && apt-get dist-upgrade -y twice.
Is there any way to optimise the above and not have redundant commands.

You can tweak this a little, but fundamentally you need two RUN apt-get update && apt-get install lines. The essential dependency chain is:
The last apt-get install line depends on having the upstream PostgreSQL repository available
You can't apt-get install from a repository until you apt-get update from it
You can't do that apt-get update without the preceding lines to add the sources.list line and load the public key
You can't get the public key without wget and gnupg
Which requires an additional apt-get install and preceding apt-get update
There's no particular need to run dist-upgrade twice and I'd skip it the first time (and maybe the second time: the Docker Hub ubuntu image is updated pretty regularly). You can combine multiple apt-get install commands together, and if you have the rm clause in there you need to run it every time. You also might consider whether you need a client library newer than what Ubuntu packages; if an older client library will work fine you can simplify this significantly.
So I might wind up somewhere like:
# Install prerequisites to install prerequisites
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --assume-yes \
gnupg2 \
wget \
&& rm -rf /var/lib/apt/lists/*
# Configure upstream PostgreSQL repository
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" | tee /etc/apt/sources.list.d/postgresql.list \
&& wget https://www.postgresql.org/media/keys/ACCC4CF8.asc \
&& apt-key add ACCC4CF8.asc
# Actually install the packages we need
RUN apt-get update && \
&& DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y \
&& DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --assume-yes \
nodejs \
postgresql-client-11 \
&& rm -rf /var/lib/apt/lists/*

Related

PostgreSQL 12 installion problem with Ubuntu 18.04 docker image

I was trying to install Postgresql-12 on an Ubuntu container, but it is giving the following error.
Reading state information...
E: Unable to locate package postgresql-12
E: Unable to locate package postgresql-client-12
It looks like the Ubuntu 18 container doesn't support PostgreSQL version 12.
Is there any way I can install postgresl version 12 on Ubuntu 18.04 container?
Any help is appreaciated. The docker file code snippet is given below.
FROM ubuntu:18.04
RUN apt-get update && apt-get install -y gnupg dirmngr
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common postgresql-12 postgresql-client-12
It seems like you are using the wrong APT package repository. Replace
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
with
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" > /etc/apt/sources.list.d/pgdg.list
and try again. precise is the codename for Ubuntu 12.04 (which has reached its end of life years ago), but your Dockerfile uses the newer Ubuntu 18.04. The codename for Ubuntu 18.04 is bionic.
Edit:
Since I'm having problems connecting to the key server given in the Dockerfile I took a look at the PostgreSQL website and aquired the key via wget as shown there. The Dockerfile does now look like this:
FROM ubuntu:18.04
RUN apt-get update && apt-get install -y gnupg dirmngr wget
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common postgresql-12 postgresql-client-12
Notable changes are the installation of wget (2nd line) and using it to get the key (4th line).

Version '100.2.1' for 'mongodb-org-tools' was not found

Background:
Quoting from the MongoDB Database Tools docs:
Starting with MongoDB 4.4, mongodump is now released separately from
the MongoDB Server and uses its own versioning, with an initial
version of 100.0.0. Previously, mongodump was released alongside the
MongoDB Server and used matching versioning.
Problem:
I'm trying to install the MongoDB Database Tools using Docker/Dockerfile:
...
RUN apt-get update
RUN apt-get install -y gnupg
RUN apt-get install -y wget
RUN wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add -
RUN echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list
RUN apt-get update
RUN apt-get install -y mongodb-org-tools=100.2.1
RUN echo "mongodb-org-tools hold" | dpkg --set-selections
...
But this line RUN apt-get install -y mongodb-org-tools=100.2.1 is giving me an error:
Version '100.2.1' for 'mongodb-org-tools' was not found
If I remove =100.2.1 the tools are installed.
But I need to specify this specific version (100.2.1) of the MongoDB Database Tools.
Question:
Is this possible? And how?
Seems to work by using:
RUN apt-get install -y mongodb-database-tools=100.2.1
Got the idea from this page:
https://docs.mongodb.com/database-tools/installation/installation-linux/
sudo dpkg -l mongodb-database-tools
sudo apt install ./mongodb-database-tools-*-100.2.1.deb
Can someone from MongoDB please confirm this is the proper way?

Install latest MongoDB on Ubuntu 16.10

I am trying to install MongoDB on Ubuntu 16.10, I have followed the steps in the MongoDB official website.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org
I followed these steps but I am getting the error:
E: Unable to locate package mongodb-org
Could this be because my Ubuntu is not 64 bit but i686?
I got a solution to this problem. Follow these steps:
sudo rm -rf /var/lib/apt/lists/*
sudo apt-get update -o Acquire::CompressionTypes::Order::=gz
sudo apt-get update && sudo apt-get upgrade
and then try to use:
sudo apt-get install -y mongodb-org
I hope it helps!

Installing MongoDb on Lubuntu

I am trying to install MongoDD on Lubuntu following the official instructions for Ubuntu.
But when I try to run this line:
sudo apt-get install -y mongodb-org
I get this error:
jon#jon-HP-ENVY-17-Notebook-PC:~$ sudo apt-get install -y mongodb-org
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package mongodb-org
jon#jon-HP-ENVY-17-Notebook-PC:~$
What am I doing wrong?
Try "sudo apt-get update" before "sudo apt-get install -y mongodb-org"...
Or try tutorial for Lubuntu, not Ubuntu, like this: http://tutorialforlinux.com/2014/03/12/how-to-install-latest-mongodb-on-lubuntu-12-04-precise-lts-32-64bit-linux-easy-guide/
May be it's beacause of the old MongoDb's version. Try with the latest MondoDb repository url to generate the file.
Before trying sudo apt-get install -y mongodb-org , execute the following commands in your terminal
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
# following is the repository url for Latest MongoDb version 3.0
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org

CDH 5.4 upgrade to HUE to 3.8

I am using CDH 5.4. I see the version of HUE is 3.7.
I want to use Spark notebook feature in HUE 3.8 but I do not know how to upgrade HUE to 3.8
I find the instruction how to update HUE at HUE wiki page. It is removed now so I place my update bash script here
#!/bin/bash
CDH_LIB=/opt/cloudera/parcels/CDH/lib
# Download tarball
wget https://dl.dropboxusercontent.com/u/730827/hue/releases/3.8.1/hue-3.8.1.tgz
# Backup old version
sudo mv $CDH_LIB/hue $CDH_LIB/hue-3.7
# Install libs
sudo apt-get -y install python2.7-dev
sudo apt-get -y install libxslt1-dev
sudo apt-get -y install libmysqlclient-dev
sudo apt-get -y install libsqlite3-dev
sudo apt-get -y install make
sudo apt-get -y install libkrb5-dev
sudo apt-get -y install libxml2-dev
sudo apt-get -y install libssl-dev
sudo apt-get -y install libldap2-dev
sudo apt-get -y install python-pip
sudo apt-get -y install libsasl2-dev
sudo apt-get -y install python-ldap
tar -zxvf hue-3.8.1.tgz
cd hue-3.8.1/
#sudo rm -rf /opt/cloudera/parcels/CDH/lib/hue
# Build
sudo PREFIX=$CDH_LIB make install
# Copy configs
sudo rsync -aL $CDH_LIB/hue-3.7/desktop/conf/ $CDH_LIB/hue/desktop/conf/
# Copy db
sudo cp $CDH_LIB/hue-3.7/desktop/desktop.db $CDH_LIB/hue/desktop/desktop.db
# Sync db
sudo $CDH_LIB/hue/build/env/bin/hue syncdb
sudo $CDH_LIB/hue migate