Installing homebrew packages during Docker build - docker

I am trying to install setup a docker image and want certain Homebrew packages pre-installed when I run the container. I am able to build it just fine and version statements are working as expected but when I run the installed packages are missing. Any idea what I am doing wrong?
RUN git clone https://github.com/Homebrew/brew ~/.linuxbrew/Homebrew \
&& mkdir ~/.linuxbrew/bin \
&& ln -s ../Homebrew/bin/brew ~/.linuxbrew/bin \
&& eval $(~/.linuxbrew/bin/brew shellenv) \
&& brew --version \
&& brew tap aws/tap && brew install aws-sam-cli \
&& sam --version

You have to set the PATH environment variable in the Dockerfile with:
ENV PATH=~/.linuxbrew/bin:~/.linuxbrew/sbin:$PATH
Here is a complete working Dockerfile:
FROM debian
RUN apt-get update && apt-get install -y git curl binutils clang make
RUN git clone https://github.com/Homebrew/brew ~/.linuxbrew/Homebrew \
&& mkdir ~/.linuxbrew/bin \
&& ln -s ../Homebrew/bin/brew ~/.linuxbrew/bin \
&& eval $(~/.linuxbrew/bin/brew shellenv) \
&& brew --version \
&& brew tap aws/tap && brew install aws-sam-cli \
&& sam --version
ENV PATH=~/.linuxbrew/bin:~/.linuxbrew/sbin:$PATH

Related

Create a Docker container for Machine Learning

I'm not a Docker expert and I'm trying to create a container for machine learning projects. This is mostly for academic purpose, as I'm studying machine learning.
I wrote a dockerfile (and a devcontainer.json file to open the container in vscode) that runs fine until I add the lines to build tensorflow. I found three problems but I don't know what I'm missing:
I got a warning about the fact that Bazel installation isn't a release version
When the building phase arrives at ./configure I can't configure through prompt question
I got an error at the very building phase with
ERROR: The project you're trying to build requires Bazel 5.3.0 (specified in /docklearning/tensorflow/.bazelversion), but it wasn't found in /usr/bin.
This is the Dockerfile:
FROM nvidia/cuda:12.0.0-runtime-ubuntu22.04 as base
ARG USER_UID=1000
#switch to non-interactive frontend
ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /docklearning
ADD . /docklearning
# Install packages
RUN apt-get update -q && apt-get install -q -y --no-install-recommends \
apt-transport-https curl gnupg apt-utils wget gcc g++ npm unzip build-essential ca-certificates curl git gh \
make nano iproute2 nano openssh-client openssl procps \
software-properties-common bzip2 subversion neofetch \
fontconfig && \
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor >bazel-archive-keyring.gpg && \
mv bazel-archive-keyring.gpg /usr/share/keyrings && \
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" \
| tee /etc/apt/sources.list.d/bazel.list && \
apt update && apt install -q -y bazel && \
apt-get full-upgrade -q -y && \
cd ~ && \
wget https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Meslo.zip && \
mkdir -p .local/share/fonts && \
unzip Meslo.zip -d .local/share/fonts && \
cd .local/share/fonts && rm *Windows* && \
cd ~ && \
rm Meslo.zip && \
fc-cache -fv && \
apt-get install -y zsh zsh-doc chroma
# Install anaconda
RUN wget https://repo.anaconda.com/archive/Anaconda3-2022.10-Linux-x86_64.sh -O Anaconda.sh && \
/bin/bash Anaconda.sh -b -p /opt/conda && \
rm Anaconda.sh
# Install LSD for ls substitute and clean up
RUN wget https://github.com/Peltoche/lsd/releases/download/0.23.1/lsd_0.23.1_amd64.deb -P /tmp && \
dpkg -i /tmp/lsd_0.23.1_amd64.deb && \
rm /tmp/lsd_0.23.1_amd64.deb && \
apt-get autoremove -y && \
apt-get autoclean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*/apt/lists/* && \
useradd -r -m -s /bin/bash -u ${USER_UID} docklearning
# Add conda to PATH
ENV PATH=/opt/conda/bin:$PATH
ENV HOME=/home/docklearning
# Make zsh default shell
RUN chsh -s /usr/bin/zsh docklearning
# link conda to /etc/profile.d
RUN ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh
# Update Conda Base env
RUN conda update -n base --all -y && \
conda install -c conda-forge bandit opt_einsum keras-preprocessing && \
conda clean -a -q -y
# Download Tensorflow from github and build from source
RUN git clone https://github.com/tensorflow/tensorflow.git && \
cd tensorflow && \
./configure && \
bazel build --config=opt --config=cuda --cxxopt="-mavx2" //tensorflow/tools/pip_package:build_pip_package && \
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg && \
pip install /tmp/tensorflow_pkg/tensorflow-*.whl && \
cd .. && \
rm -rf tensorflow
# Create shell history file
RUN mkdir ${HOME}/zsh_history && \
chown docklearning ${HOME}/zsh_history && \
mkdir ${HOME}/.ssh
# Switch to internal user
USER docklearning
WORKDIR ${HOME}
# Copy user configuration files
COPY --chown=docklearning ./config/.aliases.sh ./
COPY --chown=docklearning ./config/.bashrc ./
COPY --chown=docklearning ./config/.nanorc ./
# Configure Zsh for internal user
ENV ZSH=${HOME}/.oh-my-zsh
ENV ZSH_CUSTOM=${ZSH}/custom
ENV ZSH_PLUGINS=${ZSH_CUSTOM}/plugins
ENV ZSH_THEMES=${ZSH_CUSTOM}/themes
RUN wget -qO- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | zsh || true
RUN git clone --single-branch --branch 'master' --depth 1 https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_PLUGINS}/zsh-syntax-highlighting \
&& git clone --single-branch --branch 'master' --depth 1 https://github.com/zsh-users/zsh-autosuggestions ${ZSH_PLUGINS}/zsh-autosuggestions \
&& git clone --single-branch --depth 1 https://github.com/romkatv/powerlevel10k.git ${ZSH_THEMES}/powerlevel10k
COPY --chown=docklearning ./config/.p10k.zsh ./
COPY --chown=docklearning ./config/.zshrc ./
CMD [ "/bin/zsh" ]
I wouldn't say this question about docker or TensorFlow. It is about package installation and OS configuration.
In this case, you need to fix the bazel version first by specifying it explicitly:
apt install -q -y bazel-5.3.0
But that package is quite wired and doesn't create a symlink, so you need to create it:
ln -s /bin/bazel-5.3.0 /bin/bazel
You can validate if bazel installed by running it:
`bazel --version
bazel 5.3.0`

How to update dockerfile to update version of popper-utils' pdftotext?

I currently have a project I'm working on where the version of pdftotext from poppler-utils is using the "testing" version (found here https://manpages.debian.org/testing/poppler-utils/pdftotext.1.en.html). Instead, I want to use the version "experimental" by updating the debian image in the dockerfile (trying to avoid conflicts with other items). Is there a simple way to do this or is this not feasible?
As usual, I figured out the solution. I got some data from this post that provided some good insight on the commands. I had to update to the version that would work with my bot base but got it all figured out.
Installing Poppler utils of version 0.82 in docker
Leaving this here in case someone else encounters something similar.
FROM python:3.8-slim-buster
RUN apt-get update && apt-get install wget build-essential cmake libfreetype6-dev
pkg-config libfontconfig-dev libjpeg-dev libopenjp2-7-dev -y
RUN wget https://poppler.freedesktop.org/poppler-data-0.4.9.tar.gz \
&& tar -xf poppler-data-0.4.9.tar.gz \
&& cd poppler-data-0.4.9 \
&& make install \
&& cd .. \
&& wget https://poppler.freedesktop.org/poppler-20.08.0.tar.xz \
&& tar -xf poppler-20.08.0.tar.xz \
&& cd poppler-20.08.0 \
&& mkdir build \
&& cd build \
&& cmake .. \
&& make \
&& make install \
&& ldconfig
CMD tail -f /dev/null

Creating Docker container from Dockerfile fails on configuring bluez build

I'm trying to create a Docker container that uses Bluez. After downloading and unpacking the version that I need i use
./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var
in the directory before the make command. But every time I try to build my container using the file i get this error
checking udev directory... Package udev was not found in the pkg-config search path.
Perhaps you should add the directory containing `udev.pc'
to the PKG_CONFIG_PATH environment variable
No package 'udev' found
configure: error: udev directory is required
I'm not sure what I am doing wrong or what I can do to fix this.
The Dockerfile in question:
FROM ubuntu:18.04
USER root
WORKDIR /home/docker
COPY . /home/docker
ENV TZ=Europe/Vienna
ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-ard64/
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt update && \
apt upgrade && \
apt install -y wget && \
apt install -y git && \
apt install -y cmake && \
apt install -y openjdk-8-jdk && \
apt install -y maven && \
apt install -y libglib2.0-dev libdbus-1-dev libudev-dev libical-dev libreadline-dev && \
wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.47.tar.xz && \
tar -xf bluez-5.47.tar.xz && \
cd bluez-5.47 && \
./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var
make && \
make install

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

Laradock: Install image magik

I am trying to install image magik inside laradock
https://github.com/laradock/laradock
I have setup nginx , mysql, redis and elasticsearch.
I have tried installing the image magik inside php-fpm with
RUN apt-get -y update && \
apt-get install pkg-config libmagickwand-dev -y && \
pecl install imagick
RUN docker-php-ext-enable imagick
But still image are not generated.
I got it to working by adding following into the docker file of php-fpm for docker image of https://github.com/laradock/laradock
RUN apt-get update && apt-get install -y
git libmagick++-dev
--no-install-recommends &&
git clone https://github.com/mkoppanen/imagick.git &&
cd imagick && git checkout phpseven && phpize && ./configure &&
make && make install &&
docker-php-ext-enable imagick &&
cd ../ && rm -rf imagick
Also set PHP_FPM_INSTALL_EXIF=true in the .env next to docker-compose.yml
Remove the previous containers and images and create new build
In the .env file there is a variable for installing ImageMagick (In Laradock v7.x )
It's false by default but setting it to PHP_FPM_INSTALL_IMAGEMAGICK=true should do it.
Please try to rebuild the docker containers via the following command.
docker-compose build --no-cache
in .env file turn WORKSPACE_INSTALL_IMAGEMAGICK to true and
in workspace's Dockerfile add apt-get update &&\ on IMAGEMAGICK section like this:
###########################################################################
# ImageMagick:
###########################################################################
USER root
ARG INSTALL_IMAGEMAGICK=false
ARG IMAGEMAGICK_VERSION=latest
ENV IMAGEMAGICK_VERSION ${IMAGEMAGICK_VERSION}
RUN if [ ${INSTALL_IMAGEMAGICK} = true ]; then \
apt-get update && \
apt-get install -y libmagickwand-dev imagemagick && \
if [ $(php -r "echo PHP_MAJOR_VERSION;") = "8" ]; then \
apt-get install -y git && \
cd /tmp && \
if [ ${IMAGEMAGICK_VERSION} = "latest" ]; then \
git clone https://github.com/Imagick/imagick; \
else \
git clone --branch ${IMAGEMAGICK_VERSION} https://github.com/Imagick/imagick; \
fi && \
cd imagick && \
phpize && \
./configure && \
make && \
make install && \
rm -r /tmp/imagick; \
else \
pecl install imagick; \
fi && \
echo "extension=imagick.so" >> /etc/php/${LARADOCK_PHP_VERSION}/mods-available/imagick.ini && \
ln -s /etc/php/${LARADOCK_PHP_VERSION}/mods-available/imagick.ini /etc/php/${LARADOCK_PHP_VERSION}/cli/conf.d/20-imagick.ini && \
php -m | grep -q 'imagick' \
;fi

Resources