'DEBIAN_FRONTEND=noninteractive' not working inside shell script with apt-get - docker

I'm buildinga a docker image using a Dockerfile to build it. I have put ARG DEBIAN_FRONTEND=noninteractive in the beginning of the Dockerfile to avoid debconf warnings while building.
The warnings does not show up when using apt-get install inside the Dockerfile. However when executing a sh script (install_dependencies.sh) from the Dockerfile that contains apt-get install commands, the warnings show up again. I also tried to set DEBIAN_FRONTEND=noninteractive inside the sh script itself.
I can solve this by adding echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections in the sh script before the apt-get install commands but I would want to avoid that, since any fail in the script would leave debconf select to Noninteractive.
Dockerfile:
FROM ubuntu:18.04
# Avoid warnings by switching to noninteractive
ARG DEBIAN_FRONTEND=noninteractive
WORKDIR /tmp
# Configure APT --> HERE THE WARNINGS 'debconf: unable to initialize frontend: Dialog' ARE NOT DISPLAYED
RUN apt-get update \
&& apt-get -y upgrade \
&& apt-get install -y \
apt-utils \
dialog \
fakeroot \
software-properties-common \
2>&1
# Install APT packages --> HERE THE WARNINGS 'debconf: unable to initialize frontend: Dialog' ARE NOT DISPLAYED
RUN apt-get update && apt-get install -y \
#
# System packages
iproute2 \
procps \
lsb-release \
sudo \
unattended-upgrades \
dnsutils \
iputils-ping \
xauth \
openssl \
tar \
zip \
#
# Helpers
&& apt-get install -y \
ca-certificates \
curl \
wget \
lsof \
gconf2 \
gconf-service \
#
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
# Install LTE stack dependencies --> HERE THE WARNINGS 'debconf: unable to initialize frontend: Dialog' ARE DISPLAYED
RUN chmod +x install_dependencies.sh \
&& export DEBIAN_FRONTEND=noninteractive; ./install_dependencies.sh
install_dependencies.sh:
#!/bin/sh
export DEBIAN_FRONTEND=noninteractive
APT_PACKAGES="lib32z1 \
python-setuptools \
libmysqlclient-dev \
ninja-build"
install_apt_packages() {
sudo apt-get install -y tzdata \
build-essential \
git
for package in $APT_PACKAGES;
do
sudo apt-get -y install "$package";
done
}
main() {
sudo apt-get update && sudo apt-get upgrade -y
install_apt_packages
}
main
EDIT: Thanks to #arkadiusz-drabczyk for telling me to remove sudo from the apt-get commands, it makes perfect sense what he says, that the environment variables drop before executing the command.

Drop sudo in your script, there is point to use it if you're running as root. This is also the reason that DEBIAN_FRONTEND has no effect - sudo drops your current user's environment for security reasons, you'd have to use with -E option to make it work.

Related

Install libjpeg.so.8 Debian 11 inside Docker

I tried to integrate an application - QCPump - inside an existing Docker, with an other application - QAtrack+. The goal is to use QCPump inside QAtrack+.
The application code seems to be integrated but when I launch it, I have an error :
ImportError: libjpeg.so.8: cannot open shared object file: No such file or directory
The error is raised by the wxPython package.
Okay, so I have to install it. Unfortunately, my Docker linux is Debian 11, and Debian seems to grab this package several years ago. So, after some reseach, I found that this package is "replaced" - for Debian - by libjpeg-dev. So, I did it. And same result ...
I found the code of the librairy (wxPython) and a docker part has done for Debian 10 : https://github.com/wxWidgets/Phoenix/blob/master/docker/build/debian-10/Dockerfile
I took this part and integrated it in my DockerFile :
RUN apt-get install -y \
freeglut3 \
freeglut3-dev \
libgl1-mesa-dev \
libglu1-mesa-dev \
libgstreamer-plugins-base1.0-dev \
libgtk-3-dev \
libjpeg-dev \
libnotify-dev \
libsdl2-dev \
libsm-dev \
libtiff-dev \
libwebkit2gtk-4.0-dev \
libxtst-dev; \
apt-get clean;
But same ...
In some forum, people mentionned the LD have to be update. I tried this way but I am not pretty sure :
RUN export LD_LIBRARY_PATH=/usr/local/lib
And to be honest, I am not sure this is the problem and so the solution here...
Any idea about this problem ?
Following, my complete DockerFile if you need it ;)
FROM python:3.6
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-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 && apt-get install -y \
cron postgresql-client-10 cifs-utils dos2unix \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get install tzdata
ENV TZ 'Europe/Paris'
RUN dpkg-reconfigure -f noninteractive tzdata
RUN touch /root/.is_inside_docker
RUN pip install virtualenv
RUN date "+%H:%M:%S %d/%m/%y"
RUN apt-get -q update && \
apt-get install -yq chromium && \
rm -rf /var/lib/apt/lists/*
RUN apt-get update -y && apt-get install -y libsdl2-ttf-2.0-0 && \
apt-get update -y && apt-get install -y libjpeg-dev libaio1 libaio-dev && \
wget -q -O /tmp/libpng12.deb http://mirrors.kernel.org/ubuntu/pool/main/libp/libpng/libpng12- 0_1.2.54-1ubuntu1_amd64.deb \
&& dpkg -i /tmp/libpng12.deb \
&& rm /tmp/libpng12.deb \
&& apt-get install -y \
freeglut3 \
freeglut3-dev \
libgl1-mesa-dev \
libglu1-mesa-dev \
libgstreamer-plugins-base1.0-dev \
libgtk-3-dev \
libjpeg-dev \
libnotify-dev \
libsdl2-dev \
libsm-dev \
libtiff-dev \
libwebkit2gtk-4.0-dev \
libxtst-dev; \
apt-get clean;
RUN export LD_LIBRARY_PATH=/usr/local/lib
WORKDIR /usr/src/qatrackplus

How to run a bash script that takes multiple user intactive inputs , as part of dockerfile

I have the below dockerfile that needs to run a owasp bash file for its intallation.
This .sh file needs multiple inputs(like 1, Y, enter) from the user for the completion of installation.
How do I provide these inputs from dockerfile or is there a way to skip these inputs and continue the installation.
This dockerfile is a part of the docker-compose.
Below is thew dockerfile
FROM ubuntu:20.04
RUN apt-get update && apt-get upgrade -y && apt-get clean
RUN apt-get install python3-pip -y
RUN apt-get install vim -y
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Indian
# Install OpenJDK-8
RUN apt-get install -y openjdk-8-jdk && \
apt-get install -y ant && \
apt-get clean;
# Fix certificate issues
RUN apt-get update && \
apt-get install ca-certificates-java && \
apt-get clean && \
update-ca-certificates -f
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
RUN apt-get install wget -y && \
apt-get install unzip -y && \
apt-get install zip -y
RUN mkdir /home/owasp
RUN wget -c https://github.com/zaproxy/zaproxy/releases/download/v2.11.0/ZAP_2_11_0_unix.sh -P /home/owasp
RUN chmod u+x /home/owasp/ZAP_2_11_0_unix.sh
RUN ./home/owasp/ZAP_2_11_0_unix.sh
Use the Linux Package : https://github.com/zaproxy/zaproxy/releases/download/v2.11.0/ZAP_2.11.0_Linux.tar.gz
That has the same contents but is just a gziped tar file :)
Full list of ZAP downloads available is on https://www.zaproxy.org/download/
Or you can always extend our docker images https://www.zaproxy.org/docs/docker/
To provide input for command use some input generator and pipe it with your command.
Typical example is using command yes which provides endless stream of "y" on output:
RUN yes|./own-shell-scrpit.sh
You can run printf 'y\n1abc\nxxx' and pipe it. "\n" in printf states for newline (or enter).
I would suggest adding a ENTRYPOINT so it by default will invoke your bash script, but it gives the flexibily to the end user to pass different arguments. See the official docs. Keep in mind the CMD provided in a Dockerfile is a default command. You override it by passing any other value.
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Indian
RUN apt-get update && apt-get upgrade -y && apt-get clean
RUN apt-get install python3-pip -y
RUN apt-get install vim -y
# Install OpenJDK-8
RUN apt-get install -y openjdk-8-jdk && \
apt-get install -y ant && \
apt-get clean;
# Fix certificate issues
RUN apt-get update && \
apt-get install ca-certificates-java && \
apt-get clean && \
update-ca-certificates -f
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
RUN apt-get install wget -y && \
apt-get install unzip -y && \
apt-get install zip -y
RUN mkdir /home/owasp
RUN wget -c https://github.com/zaproxy/zaproxy/releases/download/v2.11.0/ZAP_2_11_0_unix.sh -P /home/owasp
RUN chmod u+x /home/owasp/ZAP_2_11_0_unix.sh
ENTRYPOINT ./home/owasp/ZAP_2_11_0_unix.sh
CMD ['--some', '--default', '--args']
You can even choose to pass default flags on build. So your script will then always run with default flags you provided on docker build --build-args DEFAULT_PARAMS=--foo, unless you override it:
ARGS DEFAULT_PARAMS
FROM ubuntu:20.04
ENV DEFAULT_PARAMS=${DEFAULT_PARAMS}
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Indian
RUN apt-get update && apt-get upgrade -y && apt-get clean
RUN apt-get install python3-pip -y
RUN apt-get install vim -y
# Install OpenJDK-8
RUN apt-get install -y openjdk-8-jdk && \
apt-get install -y ant && \
apt-get clean;
# Fix certificate issues
RUN apt-get update && \
apt-get install ca-certificates-java && \
apt-get clean && \
update-ca-certificates -f
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
RUN apt-get install wget -y && \
apt-get install unzip -y && \
apt-get install zip -y
RUN mkdir /home/owasp
RUN wget -c https://github.com/zaproxy/zaproxy/releases/download/v2.11.0/ZAP_2_11_0_unix.sh -P /home/owasp
RUN chmod u+x /home/owasp/ZAP_2_11_0_unix.sh
ENTRYPOINT ./home/owasp/ZAP_2_11_0_unix.sh
CMD ${DEFAULT_PARAMS}

Dockerfile Installing Selenium - Ambiguous code

Can someone explain this code to me?
# Installation required for selenium
RUN apt-get update -y \
&& apt-get install --no-install-recommends --no-install-suggests -y tzdata ca-certificates bzip2 curl wget libc-dev libxt6 \
&& apt-get install --no-install-recommends --no-install-suggests -y `apt-cache depends firefox-esr | awk '/Depends:/{print$2}'` \
&& update-ca-certificates \
# Cleanup unnecessary stuff
&& apt-get purge -y --auto-remove \
-o APT::AutoRemove::RecommendsImportant=false \
&& rm -rf /var/lib/apt/lists/* /tmp/*
Why is it necessary to put this in a Dockerfile for selenium to run? (tested and won't run without the code). Why doesn't it simply work by using pip to install the selenium dependency?
Source: Firefox(headless)+selenium cannot access internet from docker container

Dockerfile from python:3.6-slim add jdk8

someone could help me, i'm starting from follow docker file
FROM python:3.6-slim
RUN apt-get update
RUN apt-get install -y apt-utils build-essential gcc
And i would add an openjdk 8
thanks
You can download java tar.gz, unpack it and set environment variable.
Below a sample of implementation in Dockerfile:
FROM python:3.6-slim
RUN apt-get update
RUN apt-get install -y apt-utils build-essential gcc
ENV JAVA_FOLDER java-se-8u41-ri
ENV JVM_ROOT /usr/lib/jvm
ENV JAVA_PKG_NAME openjdk-8u41-b04-linux-x64-14_jan_2020.tar.gz
ENV JAVA_TAR_GZ_URL https://download.java.net/openjdk/jdk8u41/ri/$JAVA_PKG_NAME
RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/* && \
apt-get clean && \
apt-get autoremove && \
echo Downloading $JAVA_TAR_GZ_URL && \
wget -q $JAVA_TAR_GZ_URL && \
tar -xvf $JAVA_PKG_NAME && \
rm $JAVA_PKG_NAME && \
mkdir -p /usr/lib/jvm && \
mv ./$JAVA_FOLDER $JVM_ROOT && \
update-alternatives --install /usr/bin/java java $JVM_ROOT/$JAVA_FOLDER/bin/java 1 && \
update-alternatives --install /usr/bin/javac javac $JVM_ROOT/$JAVA_FOLDER/bin/javac 1 && \
java -version
In cases where you need python and java installed in a same image (i.e. pyspark) I find it easier to extend the openjdk images with python than the other way around for example:
FROM openjdk:8-jdk-slim-buster
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
curl \
python3.7 \
python3-pip \
python3.7-dev \
python3-setuptools \
python3-wheel
Build the image: docker build --rm -t so:64051125 .
Note: the version of python3 available through apt on debian:buster-slim is 3.7, if you really need 3.6 could try building it from source.
Up to today (17/02/2021) openjdk-8-jdk is still in debian 9 (Strech) but removed from debian 10 (Buster), so you should find openjdk-8-jdk if you use this python docker image: python:3.6-stretch instead of python:3.6-slim-buster

Can't connect to SQL Server from elixir/phoenix in Docker

I'm trying to connect a "Phoenix (Elixir)-Application" (packed as Docker-Container) to microsoft/mssql-server-linux:latest Docker-Container
Therefore I'm using https://hex.pm/packages/mssql_ecto as Adapter
use Mix.Config
config :my_api, MyApi.Repo,
adapter: MssqlEcto,
database: "dev",
username: "sa",
password: "my_api_password",
hostname: "127.0.0.1",
#odbc_driver: "{SQL Server Native Client 11.0}",
#odbc_driver: "{ODBC Driver 11 for SQL Server}",
#odbc_driver: "{ODBC Driver 13.1 for SQL Server}",
#odbc_driver: "{ODBC Driver 13 for SQL Server}", # <- Default
#port: "1433" # <- Default
My current Dockerfile for running the phoenix-Application in Docker:
FROM elixir:1.5.2
# install ODBC driver
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y curl apt-transport-https debconf-utils apt-utils
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update -y && ACCEPT_EULA=Y apt-get install -y msodbcsql && ACCEPT_EULA=Y apt-get install -y mssql-tools && apt-get install -y unixodbc-dev
RUN apt-get install -y erlang-odbc
I guess the problem is located in my Dockerfile, especially the lines for installing the ODBC driver. When you look at my Mix.Config, you see that i tried many combinations of "odbc-driver"-strings - not one of them works..
heres the output of the phoenix start:
** (Mix) The database for MyApi.Repo couldn't be created: %Mssqlex.Error{constraint_violations: [], message: "[unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2270.0' : file not found Connection to database failed. | ODBC_CODE 01000 | SQL_SERVER_CODE 0", odbc_code: "01000"}
Is anybody out there whos got a working Elixir (docker-image) with the possibility to connect to "microsoft/mssql-server-linux:latest Docker-Container"?
Im very thankful for any help!
BTW ... im able to connect to the "mssql-server-linux Container" from Host via HeidiSQL and
Microsoft SQL Server Management Studio 17 => so no problems with "mssql-server-linux Container" at all.
Setup:
HOST OS: Windows 10 Pro
Docker for Windows: 17.12.0-ce-win47
For all struggling with this: here are the relevant lines of my working Dockerfile for Ubuntu 16:
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install apt-utils apt-transport-https wget
RUN echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/mssql-ubuntu-xenial-release/ xenial main" > /etc/apt/sources.list.d/mssqlpreview.list
RUN apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
RUN apt-get -y update
RUN env ACCEPT_EULA=Y DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential \
cpanminus \
msodbcsql \
unixodbc-dev-utf16
RUN apt-get install unixodbc-dev-utf16
RUN cd /root && \
wget https://cpan.metacpan.org/authors/id/M/MJ/MJEVANS/DBD-ODBC-1.56.tar.gz && \
tar xf DBD-ODBC-1.56.tar.gz && \
cd /root/DBD-ODBC-1.56 && \
perl Makefile.PL -u && \
cpanm --installdeps . && \
make && \
make test && \
make install && \
rm -rf /root/DBD-ODBC-1.56.tar.gz /root/DBD-ODBC-1.56
# Set locale
RUN apt-get install -y locales
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
The last lines are important for the ODBC-Driver to work properly.
odbc_driver: "{ODBC Driver 13 for SQL Server}
for a working MssqlEcto-Configuration!
#Nolan: i was very happy when i get it working with Ubuntu, i switched instantly to Debian (elixir 1.6) - it works. but u have to change some parts. Heres my working Dockerfile for elixir.1.6 (debian) - let me if it works with 1.6.1
BTW: the odbc driver is very bitchy when is comes to wrong locale configuration ;)
FROM elixir:1.6
ENV REFRESHED_AT 29-01-2018
# install odbc driver
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install apt-utils apt-transport-https wget
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN env ACCEPT_EULA=Y DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential \
cpanminus \
msodbcsql \
unixodbc-dev
RUN apt-get install unixodbc-dev
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql
RUN ACCEPT_EULA=Y apt-get install -y mssql-tools
RUN cd /root && \
wget https://cpan.metacpan.org/authors/id/M/MJ/MJEVANS/DBD-ODBC-1.56.tar.gz && \
tar xf DBD-ODBC-1.56.tar.gz && \
cd /root/DBD-ODBC-1.56 && \
perl Makefile.PL -u && \
cpanm --installdeps . && \
make && \
make test && \
make install && \
rm -rf /root/DBD-ODBC-1.56.tar.gz /root/DBD-ODBC-1.56
# set locale configuration
RUN apt-get install -y locales
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8
# install hex
RUN mix local.hex --force
# install rebar
RUN mix local.rebar --force
# install phoenix
RUN mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez --force
# install node
RUN curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh
RUN bash nodesource_setup.sh
RUN apt-get install nodejs
IDK if this is production ready (in sense of security and optimizing) - when u get an optimized version please let me know! cheers

Resources