How do I answer install prompts (other than with "yes") automatically? - dockerfile

Synopsis
I'm trying to build a Docker image, but it fails because one of the packages I'm trying to get with apt install prompts the user during the install process. I would like to reply to this prompt, but I can't figure out how to do it non-interactively.
Description
I'm building a Docker image, and my Dockerfile has the following line:
RUN apt install -y texlive-latex-extra
(This package has some LaTeX libraries that I need.)
During installation, this halts with:
Setting up tzdata (2018d-1) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
Configuring tzdata
------------------
Please select the geographic area in which you live. Subsequent configuration
questions will narrow this down by presenting a list of cities, representing
the time zones in which they are located.
1. Africa 6. Asia 11. System V timezones
2. America 7. Atlantic Ocean 12. US
3. Antarctica 8. Europe 13. None of the above
4. Australia 9. Indian Ocean
5. Arctic Ocean 10. Pacific Ocean
Geographic area:
At this point, it is waiting for some input. (There's another prompt after this for selecting timezone—I assume this is important to know for the \today directive in LaTeX files. ¯\_(ツ)_/¯)
How can I answer this non-interactively?
What I've tried so far
I've tried doing this:
apt install -y texlive-latex-extra <(echo 12 && echo 2)
and this:
echo 12 && echo 2 | apt install -y texlive-latex-extra
The first one died with this error:
apt install -y texlive-latex-extra <(echo 12 && echo 9)
and the second one seemed to have no effect.
For reference, here is my Dockerfile up until this point:
FROM ubuntu:latest
RUN apt update && apt upgrade -y && apt install -y curl bzip2 tar make gcc wget gnupg unzip
RUN apt install -y texlive
RUN apt install -y nodejs npm git
RUN npm install -g bower
RUN apt install -y texlive-latex-extra
UPDATE
I found something close here which suggested running apt install with DEBIAN_FRONTEND=noninteractive. This solved my problem sufficiently. :) However, I still would like to know how to respond to prompts, as the solution offered there only offered how to suppress them.

If you want to script a terminal interaction, you could use expect on Linux (that might not be very easy; you need to predict the interactions).
Remember that terminal emulators are complex and arcane things (because terminals like VT100 have been complex). See termios(3), pty(7) and read The Tty demystified.

The specific install prompt mentioned in the question is caused by the package tzdata. I managed to get it configured non-interactively in my docker build by setting these environment variables:
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y texlive-luatex texlive-latex-extra texlive-font
I found this solution over here: https://serverfault.com/questions/949991/how-to-install-tzdata-on-a-ubuntu-docker-image

Related

What's this error about while adding postgis in docker [duplicate]

This question already has answers here:
How to fill user input for interactive command for "RUN" command?
(2 answers)
Closed 6 months ago.
Part of my Dockerfile is as:
RUN apt-get install -yqq software-properties-common
RUN add-apt-repository ppa:ubuntugis/ppa && apt-get update -yqq
RUN apt-get install -yqq gdal-bin
RUN apt-get install -yqq postgis
I installed postgis repo, then installing postgis, but when it got to the installation step of postgis, I get this prompt on the screen & it's stuck there.
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
Configuring tzdata
------------------
Please select the geographic area in which you live. Subsequent configuration
questions will narrow this down by presenting a list of cities, representing
the time zones in which they are located.
1. Africa 4. Australia 7. Atlantic 10. Pacific 13. Etc
2. America 5. Arctic 8. Europe 11. SystemV
3. Antarctica 6. Asia 9. Indian 12. US
Geographic area:
Does anyone has any idea??
Use RUN DEBIAN_FRONTEND=noninteractive apt-get install -yqq postgis when install postgis to suppress the dialog, or use ARG DEBIAN_FRONTEND=noninteractive which will also not persist to container but still have same effect.
Maybe also refers to https://github.com/docker/docker/issues/4032

RHEL: This system is currently not set up to build kernel modules

I am trying to install virtualbox5.2 on a RHEL 7 VM When I try to rebuild kernels modules I get the following error:
[root#myserver~]# /usr/lib/virtualbox/vboxdrv.sh setup
vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.
This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
kernel-devel kernel-devel-3.10.0-693.11.1.el7.x86_64
I tried install kernet-devel and got success message
Installed:
kernel-devel.x86_64 0:3.10.0-693.21.1.el7
Complete!
But still the setup fails.
Any idea what is missing here?
sudo yum install -y "kernel-devel-$(uname -r)"
Substitute dnf on Fedora. I didn't need to do a reboot, but ymmv.
Edit for 2020:
Centos/RHEL 8 now also use dnf instead of yum. I haven't had occasion to test this on those distros, so the same YMMV disclaimer still applies.
First run in terminal: uname -r then you will get name and information about current kernel (CURRENT_KERNEL).
Now you can install with command: yum install kernel-devel-CURRENT_KERNEL
Note: replace CURRENT_KERNEL with string you get from uname -r.
The same message happened when I tried to upgrade VirtualBox 5.2.12 Guest Additions on my Kali Linux (GNU/Linux Rolling version). I fixed it by following steps:
Do apt update/upgrade to keep your system up-to-date. Do not forget to reboot the system.
Run "apt-get install linux-headers-$(uname -r)".
Run VBoxLinuxAdditions.run from terminal, error message gone and Guest Additions will be installed successfully.
Reboot system, Guest Additions works fine.
I got here looking for the same answer for CentOS 6, and the above answers worked with slight modification (so, for anyone else that lands here too)...
yum install -y kernel-devel kernel-devel-$(uname -r)
So, "yum" instead of "apt-get"
Also, some Linux use "linux-headers" instead of "kernel-devel" but the principle seems to be the same.
The kernel your were using was kernel-devel-3.10.0-693.11.1.el7.x86_64 is slightly different with the one that you installed kernel-devel.x86_64 0:3.10.0-693.21.1.el7 . In my case, there are several different version installed on my OS, and "sudo yum install kernel-devel" always install the newest one for me. Then I work it out by setting my default kernel version as same as yum installed for me. You can check the kernel you have installed on your OS by following command:
sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
Then just set the kernel version you choose to use as same as yum choose for you,by following command:(notice that the number at last is pick up from preceding command result),
sudo grub2-set-default 0
generate the grub2 config with 'gurb2-mkconfig' command, and then reboot the server.
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
sudo reboot
Milan Rakos is right. Your installed kernel-devel must have suffix string exactly the same as the uname -r output. Besides, the logs during the vboxdrv.sh setup also shows the wanted version of the kernel-devel.
So to your case, You will run the command:sudo yum install kernel-devel-3.10.0-693.11.1.el7.x86_64
to solve this problem I ran yum update -y. I think this is the fastest way to solve it. Another solution is to configure the repos with the installation DVD, so you can install the kernel-headers of your current version of CentOS.
My History:
yum install epel-release
yum install perl gcc dkms kernel-devel kernel-headers make bzip2
yum groupinstall "Development tools"
yum update -y
reboot
After that, I mount de VBoxGuestAdditions and I ran the process
yum install kernel-devel-3.10.0-693.11.1.el7.x86_64 fixed the issue.
A little late to the party but I just ran into this problem myself and here's what I did to resolve the issue.
yum update -y
yum install -y redhat-lsb-core net-tools kernel-headers kernel-devel epel-release
yum groupinstall -y "Development Tools"
reboot
Ensure your system has been fully updated when you ran yum update -y before continuing!
Cheers

installing php-imap on amazon ec2 linux 2

I need to install php-imap on amazon ec2 linux 2 instance.
All the php stuff is inside amzn2extra-lamp-mariadb10.2-php7.2 but php-imap package is missing.
Any advice ?
Thanks
I installed it like this.
I downloaded the php source code of the currently installed version in my Amazon Linux 2
wget http://php.net/get/php-7.2.8.tar.bz2/from/a/mirror
Unpacked it and went into php-7.2.8/ext/imap/
Compiled extension:
phpize
./configure
I got some errors.
Some U8T_CANONICAL stuff so
sudo yum install libc-client-devel
Then libc-client.a not found so created a symlink for it:
cd /usr/lib
sudo ln -s /usr/lib64/libc-client.a
some other imap library error so:
sudo yum install uw-imap-static
I got some other errors so the working configure line was:
./configure --with-kerberos --with-imap-ssl
make
SUCCESS!
cd php-7.2.8/ext/imap/modules
sudo cp imap.so /usr/lib64/php/modules/
Created an ini file to load it:
sudo vi /etc/php.d/30-imap.ini
added to the file this content:
extension=imap
restarted php service (you might need to restart httpd depending on your php installation):
sudo systemctl restart php-fpm
PHPinfo now contains:
imap
IMAP c-Client Version 2007f
SSL Support enabled
Kerberos Support enabled
For those who are facing the U8T_CANONICAL error and can't being able to install the libc-client-devel on Amazon Linux 2 AMI need to do something extra to resolve the U8T_CANONICAL error.
The main problem is that libc-client-devel isn't available so we need to do it in another way.
I found this link while searching for my problem. The solution that is posted here is solid. The following link that i gave is for those who are not being able to install the libc-client-devel will be benifited from the link.
Or you could just copy paste the commands i'm giving below.
1 - sudo yum groupinstall "Development Tools"
2 - sudo amazon-linux-extras install epel
3 - yum install epel-release
4 - sudo yum install libc-client-devel uw-imap-static openssl-devel
5 - sudo ln -s /usr/lib64/libc-client.a /usr/lib
The rest can be followed from respondent.
Again thanks to the person who answered.
Same problem here.
I came from debian/ubuntu and i miss a lot of php packages on aws linux2.
I know it's still a candidate and not a final LTS release. Only worked for a month with this distro and saw a lot of changes and updates. Some php dependencies can be solved with pear or pecl, but I couldn't get nothing working on php-imap.
php-imap depends on libc-client (maybe that's a problem?)
Here is my solution.
Search for the libc-client rpm that correspond to your version and
install manually.
Search for the rpm that corresponds to your php installed version. In my case it was 7.2.5**-2** about 2 weeks ago. (today is
7.2.5**-3** ) and isntall manually
CODE
wget https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64//php72u-imap-7.2.5-2.ius.centos7.x86_64.rpm -P /tmp
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/l/libc-client-2007f-16.el7.x86_64.rpm -P /tmp
rpm -i /tmp/libc-client-2007f-16.el7.x86_64.rpm
rpm -i /tmp/php72u-imap-7.2.5-2.ius.centos7.x86_64.rpm
If it fails because Failed dependencies:
rpm -ivh /tmp/php72u-imap-7.2.5-2.ius.centos7.x86_64.rpm --nodeps
I dont like this solution, but can't find for now any other solution more stable and easy. It will be a pain with updates....

not able to install contextBroker via yum on CentOs7

HI everybody i am using CentOs7 and havae some troubles with the installation of the contextBroker. I followed the installation on the added the Fiware Repo in my yum repo.
Here is a list of my yum repo:
repo id repo name status
base/7/x86_64 CentOS-7 - Base 9,007
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 10,368
extras/7/x86_64 CentOS-7 - Extras 356
fiware Fiware Repository 176
mongodb MongoDB repo 279
updates/7/x86_64 CentOS-7 - Updates 2,070
repolist: 22,256
I am always getting an error message that there are some failed dependencies
libboost_filesystem-mt.so.5()(64bit) is needed by contextBroker-0.15.0-1.x86_64
libboost_system-mt.so.5()(64bit) is needed by contextBroker-0.15.0-1.x86_64
libboost_thread-mt.so.5()(64bit) is needed by contextBroker-0.15.0-1.x86_64
Here is the output of my config file for the fiware.repo
[fiware]
name=Fiware Repository
#baseurl=http://repositories.lab.fiware.org/repo/rpm/$releasever
baseurl=http://repositories.lab.fiware.org/repo/rpm/x86_64/
gpgcheck=0
enabled=1
I found a possible solution under this link, but unfortunately this is not working. In the comment section there is an entry which says that there is a problem with CentOs7 but that doesn`t solve my problem
Btw: this is also not working Boost-Libboost is needed in Centos7 (ContexBroker)
So my question is, did someone installed the contextBroker on CentOs7 via yum and if he/she did how can i solve this problem ?
As you mention, there isn't official support for CentOS 7 at the present moment. However, you could do the following to get a running binary with contextBroker in your CentOS 7 system (actually, this a "quick and dirty" receipt based on the build from sources procedure documented in the Orion manual):
sudo yum install git wget
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo rpm -i epel-release-latest-7.noarch.rpm
sudo yum install make cmake gcc-c++ scons
sudo yum install boost-devel libcurl-devel gnutls-devel libgcrypt-devel libuuid-devel
# Install mongoDB driver as described in the documentation
# Install rapidjson as described in the documentation
# Install libmicrohttpd as described in the documentation
mkdir ~/src
cd ~/src
git clone https://github.com/telefonicaid/fiware-orion.git
cd fiware-orion
# optionally, you can set an specific version with a checkout command
# e.g. 'git checkout 1.2.1'. Otherwise, you will build the latest
# code from develop branch
make
BUILD_RELEASE/src/app/contextBroker/contextBroker --version
Moreover, you can use the following to generate a RPM file:
sudo yum install rpm-build
make rpm
# The RPM is generated in rpm/RPMS/x86_64/contextBroker-1.2.0_next-dev.x86_64.rpm
# (version number may vary)
That RPM file is supposed to work in other CentOS 7 systems and you can install just using sudo yum install /path/to/contextBroker-1.2.0_next-dev.x86_64.rpm.

How do I install extra python packages on Datalab if they are not supported by pip?

I tried to install basemap within Datalab using pip:
%bash
pip install basemap
and got the error:
Downloading/unpacking basemap
Could not find any downloads that satisfy the requirement basemap
Cleaning up... No distributions at all found for basemap
Storing debug log for failure in /root/.pip/pip.log
How do I install extra packages on Datalab if they are not supported by pip?
Use apt-get install. In a cell of your notebook:
%bash
apt-get -y update
apt-get -y install python-mpltoolkits.basemap
Then, remember to restart your kernel (by Reset Session)
Use the following code for this:
%%bash
pip install package_name
You might need to first do
apt-get update
So it gets the updated list of packages.
Basemap doesn't come with the google datalab out of the box.
Note: I use shorthand '!' to indicate a bash command, rather than '%bash' as the google documents usually do.
As of Feb 2019, this works on a fresh google datalab:
Step 1: Install Pre-requisites
!apt-get update && apt-get install -y --allow-unauthenticated build-essential libgeos-3.5.0 libgeos-c1v5 libgeos++-dev
!pip install pyproj pyshp
Step 2: Install the whole package
!pip install https://downloads.sourceforge.net/project/matplotlib/matplotlib-toolkits/basemap-1.0.7/basemap-1.0.7.tar.gz
Step 3: Check the package has been installed correctly
!pip freeze
Step 4: Import the module
from mpl_toolkits.basemap import Basemap
#Lak: You will need to update page 155 of your book - Data Science on the Google Cloud platform as the instructions there won't work; basemap is one of the more difficult packages to get working.
The command suggested by Lak might have worked in the past but it's no longer the case: as of today (Aug 2017) Google Datalab instances reject the command listed here
%bash
echo 'Y' | apt-get install python-mpltoolkits.basemap
outputs the error message:
E: Unable to locate package python-mpltoolkits.basemap
E: Couldn't find any package by regex 'python-mpltoolkits.basemap'
Execution from the shell (vs. notebook) outputs the same error.
After searching various sources I found a fix that worked for me: from the notebook in Datalab I added an update cmd before the actual install, like this:
%bash
echo 'Y' | apt-get update
echo 'Y' | apt-get install python-mpltoolkits.basemap