running windows base application embedded in ubuntu or alpine based docker image - docker

We developed Windows based application and try to convert it to run as docker in Linux base environment.
Unfortunately, one of 3rd party library can't be convert to Linux environment.
We built docker image which is ubuntu 16.04 + wine 4.0 + winetricks which our application can runs on it but all 3 components (ubuntu, wine + winetrick) weight more than 3GB.
Below is the part of Dockerfile which we use to build the docker image
Our application is 64bit and combines python and C++ code
How can we reduce docker size?
Is there another way to run windows base application as docker container on linux environment?
FROM ubuntu:16.04
# reccomended to add 32bit arch for wine
RUN dpkg --add-architecture i386 \
# install things to help install wine
&& apt-get update \
&& apt-get install -y --allow-unauthenticated wget software-properties-common software-properties-common debconf-utils python-software-properties apt-transport-https cabextract telnet xvfb unzip build-essential \
# register repo and install winehq
&& wget -nc https://dl.winehq.org/wine-builds/Release.key \
&& apt-key add Release.key \
&& wget -nc https://dl.winehq.org/wine-builds/winehq.key \
&& apt-key add winehq.key \
&& apt-add-repository https://dl.winehq.org/wine-builds/ubuntu/ \
&& apt-get update \
&& apt-get install -y xvfb \
&& apt-get install --install-recommends -y --allow-unauthenticated winehq-stable
# setup vars for wine
ENV DISPLAY=":0.0"
ENV WINEARCH="win64"
ENV WINEPREFIX="/root/.wine64"
ENV WINESYSTEM32="/root/.wine64/drive_c/windows/system32"
ENV WINEDLLOVERRIDES="mscoree,mshtml="
ENV WINEDEBUG=-all
COPY scripts /root/scripts
# pull down winetricks, and install requirements
# vcrun2015 and vcrun2010 are Visual Studio C++ Redistributables
RUN set -e \
&& mkdir -p $WINEPREFIX \
&& cd $WINEPREFIX \
&& wget https://raw.githubusercontent.com/Winetricks/winetricks/20190615/src/winetricks \
&& chmod +x winetricks \
&& xvfb-run wine wineboot --init \
&& xvfb-run wineserver -w \
&& xvfb-run sh ./winetricks -q d3dx9 corefonts vcrun2015
RUN set -x \
&& pythonVersions='python3.7' \
&& apt-get update \
&& apt-get install -y --allow-unauthenticated --no-install-recommends software-properties-common \
&& apt-add-repository -y ppa:deadsnakes/ppa \
&& apt-get update \
&& apt-get install -y --allow-unauthenticated --no-install-recommends $pythonVersions \
&& rm -rf /var/lib/apt/lists/* \
...

You install many unneeded packages, you should read carefully
https://www.dajobe.org/blog/2015/04/18/making-debian-docker-images-smaller/
which explains why
You should remove xvfb (I guess you need xvfb during the installation and configuration of wine, but not after) and all the "recommended" packages
Look also at
https://github.com/wagoodman/dive
which is an excellent tool if you need to see how efficient is your docker image
Use also
https://github.com/jwilder/docker-squash
it can save some space.
Good hunt

Related

Shiny app (leafviz) in docker container not loading in browser

I am building a docker container to use the Leafcutter and Leafviz analysis tools. The final visualization commanded from an R file uses shiny app, it works fine on my machine but when ran in the container I can't connect to it.
I run the container with the following line of code:
docker run -dit --name leaf --rm -p 1234:1234 leafcutter
All is in order when I check with docker ps:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
783f550df965 leafcutter "bash" 2 minutes ago Up 2 minutes 0.0.0.0:1234->1234/tcp, :::1234->1234/tcp leaf
Executing the pipeline in the container calls several snakefiles, and the last rule of the last one calls the R file:
Rscript /path/to/run_leafviz.R -i {input}
That script calls several functions before calling leafviz() which basically just runs the shiny app, I've modified the options like so:
shiny::runApp(launch.browser=FALSE, appDir = system.file("application", package = "leafviz"), host = "0.0.0.0", port = 1234)
All the shiny files and packages are installed with the R leafviz package. When I execute my container all goes fine, the output shows "Listening on http://0.0.0.0:1234", but when I try to connect I get the "connexion failed" page.
My Dockerfile is fairly large but here are the most relevant parts:
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND noninteractive
#Install Ubuntu packages
RUN apt-get update && apt-get install \
-y cmake -y curl \
-y default-jre \
-y gdebi-core \
-y less -y libarchive13 -y libbz2-dev -y libcairo2-dev -y libcurl4-openssl-dev -y libgsl-dev \
-y liblzma-dev -y libncurses5-dev -y libncursesw5-dev -y libssl-dev -y libxml2-dev -y libxt-dev \
-y pandoc -y pandoc-citeproc -y python-pip \
-y tabix \
-y unzip \
-y wget \
-y zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
#Install conda, snakemake, samtools, regtools...
#[...]
#Install R
LABEL org.label-schema.license="GPL-2.0" \
org.label-schema.vcs-url="https://github.com/rocker-org/r-apt" \
org.label-schema.vendor="Rocker Project" \
maintainer="Dirk Eddelbuettel <edd#debian.org>"
RUN useradd docker \
&& mkdir /home/docker \
&& chown docker:docker /home/docker \
&& addgroup docker staff
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
littler r-base r-base-dev r-recommended r-cran-docopt
RUN ln -s /usr/lib/R/site-library/littler/examples/install.r /usr/local/bin/install.r \
&& ln -s /usr/lib/R/site-library/littler/examples/install2.r /usr/local/bin/install2.r \
&& ln -s /usr/lib/R/site-library/littler/examples/installGithub.r /usr/local/bin/installGithub.r \
&& ln -s /usr/lib/R/site-library/littler/examples/testInstalled.r /usr/local/bin/testInstalled.r \
&& rm -rf /tmp/downloaded_packages/ /tmp/*.rds \
&& rm -rf /var/lib/apt/lists/*
#Install shiny server (I have tried with and without this RUN command)
RUN wget --no-verbose https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/VERSION -O "version.txt" && \
VERSION=$(cat version.txt) && \
wget --no-verbose "https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/shiny-server-$VERSION-amd64.deb" -O ss-latest.deb && \
gdebi -n ss-latest.deb && \
rm -f version.txt ss-latest.deb
EXPOSE 1234
#Install R packages
COPY install_packages.R /tmp/install_packages.R
RUN Rscript /tmp/install_packages.R
CMD ["bash"]
I've been learning docker quite chaotically so I don't know if some elements are clashing, but I have exposed the container port and published it to the host and no error message seems to indicate there is a problem coming from somewhere else. I would really appreciate some help.

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

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.

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

Running headless Chrome with webgl and Nvidia GPU inside a container

I'm trying to run headless chrome inside a docker container with the webgl support and the hardware acceleration.
I have a Nvidia graphic card and if I test of the drivers with the command suggested by Nvidia, it is successful
docker run --gpus all nvidia/opengl:base nvidia-smi
This is my dockerfile :
FROM nvidia/opengl:1.0-glvnd-runtime-ubuntu18.04
# Env vars for the nvidia-container-runtime.
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES all
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
ca-certificates \
build-essential \
g++ \
libxinerama-dev \
libxext-dev \
libxrandr-dev \
libxi-dev \
libxcursor-dev \
libxxf86vm-dev \
libvulkan-dev && \
rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y apt-utils && apt-get install -y curl
RUN apt-get update \
&& apt-get install -y wget gnupg ca-certificates \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
# We install Chrome to get all the OS level dependencies, but Chrome itself
# is not actually used as it's packaged in the node puppeteer library.
# Alternatively, we could could include the entire dep list ourselves
# (https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix)
# but that seems too easy to get out of date.
&& apt-get install -y google-chrome-stable \
&& rm -rf /var/lib/apt/lists/* \
&& wget --quiet https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -O /usr/sbin/wait-for-it.sh \
&& chmod +x /usr/sbin/wait-for-it.sh
# Install GTK, pulseaudio and fonts
RUN apt-get update && \
apt-get -y --no-install-recommends install ca-certificates tzdata \
libcanberra-gtk-module libexif12 pulseaudio attr \
fonts-dejavu-core fonts-freefont-ttf fonts-guru-extra \
fonts-kacst fonts-kacst-one fonts-khmeros-core fonts-lao \
fonts-liberation fonts-lklug-sinhala fonts-lohit-guru \
fonts-nanum fonts-opensymbol fonts-sil-abyssinica \
fonts-sil-padauk fonts-symbola fonts-takao-pgothic \
fonts-tibetan-machine fonts-tlwg-garuda-ttf \
fonts-tlwg-kinnari-ttf fonts-tlwg-laksaman-ttf \
fonts-tlwg-loma-ttf fonts-tlwg-mono-ttf \
fonts-tlwg-norasi-ttf fonts-tlwg-purisa-ttf \
fonts-tlwg-sawasdee-ttf fonts-tlwg-typewriter-ttf \
fonts-tlwg-typist-ttf fonts-tlwg-typo-ttf \
fonts-tlwg-umpush-ttf fonts-tlwg-waree-ttf \
ttf-bitstream-vera ttf-dejavu-core ttf-ubuntu-font-family \
fonts-arphic-ukai fonts-arphic-uming \
fonts-ipafont-mincho fonts-ipafont-gothic \
fonts-unfonts-core && \
rm -rf -- /var/lib/apt/lists /tmp/*.deb
however when I run the container with :
docker run -it --gpus all mytest
and I try to capture a screenshot inside the container with:
google-chrome --no-sandbox --headless --screenshot=ss.png chrome://gpu/
I get the error : Segmentation fault (core dumped)
Any idea ?
GPU chome headless options are still problematic, especially when You try that in containers. Just update image to current nvidia/opengl:1.2-glvnd-runtime-ubuntu20.04 and You will get output without any memory dump. I had same issues about year ago on some chrome options with vulkan support (now same thing works ok).

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