We were wondering how to parameterize the building process. We have an application that can have features if the right libraries are there at compile time. Also, we optionally would like to include some other debugging applications into the same image.
Our current strategy is to comment-in/out lines in the Dockerfile and compile it to another name.
# Dockerfile in multiple variants / t-shirt sizing:
# - as is, with all the #something; comments: very basic compilation without features
# - removing #something; enable a variant/feature
# see build and test instructions below
###
# REQUIRED: INSTALL COMPILER, DOWNLOAD AND INSTALL BITS AND PIECES
###
# start from a fedora 28 image
FROM fedora:28 AS compiler_build
RUN echo "############################# COMPILER IMAGE #################################"
# install requirements
#RUN dnf upgrade -y && dnf clean all
RUN dnf install -y git gcc gcc-c++ make automake autoconf gettext-devel
#######
# OPTIONAL: CAM SUPPORT
#######
#cam;RUN dnf install -y wget mercurial patch glibc-static
#cam;
#cam;# do not use pre-built dvb-apps and libdvbcsa from distro-mirror, but build from sources. This is required for cam support on fedora.
#cam;RUN cd /usr/local/src && \
#cam; hg clone http://linuxtv.org/hg/dvb-apps && \
#cam; cd dvb-apps && \
#cam; # patching for >=4.14 Kernel (https://aur.archlinux.org/packages/linuxtv-dvb-apps)
#cam; wget -q -O - https://git.busybox.net/buildroot/plain/package/dvb-apps/0003-handle-static-shared-only-build.patch | patch -p1 && \
#cam; wget -q -O - https://git.busybox.net/buildroot/plain/package/dvb-apps/0005-utils-fix-build-with-kernel-headers-4.14.patch | patch -p1 && \
#cam; wget -q -O - https://gitweb.gentoo.org/repo/gentoo.git/plain/media-tv/linuxtv-dvb-apps/files/linuxtv-dvb-apps-1.1.1.20100223-perl526.patch | patch -p1 && \
#cam; make && make install && \
#cam; ldconfig # b/c libdvben50221.so
#######
# OPTIONAL: SCAM SUPPORT
#######
#scam;RUN yum install -y openssl-devel dialog svn pcsc-lite pcsc-lite-devel libusb libusb-devel findutils file libtool
#scam;
#scam;RUN cd /usr/local/src && \
#scam; git clone https://code.videolan.org/videolan/libdvbcsa.git && \
#scam; cd libdvbcsa && \
#scam; autoreconf -i -f && \
#scam; ./configure --prefix=/usr && make && make install && \
#scam; ldconfig # b/c libdvbcsa.so
#scam; #dnf install -y https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm && \
#scam; #dnf install -y libdvbcsa-devel
#scam;
#scam;RUN cd /usr/local/src && \
#scam; svn checkout http://www.streamboard.tv/svn/oscam/trunk oscam-svn && \
#scam; cd oscam-svn && \
#scam; make USE_PCSC=1 USE_LIBUSB=1
#scam;
#scam;RUN cd /usr/local/src && \
#scam; git clone https://github.com/gfto/tsdecrypt.git && \
#scam; cd tsdecrypt && \
#scam; git submodule init && \
#scam; git submodule update && \
#scam; make && make install
#######
# REQUIRED: ACTUAL APPLICATION ITSELF
#######
# note: the ./configure will detect cam/scam support automagically if everything provided
RUN cd /usr/local/src && \
ldconfig && \
git clone https://github.com/braice/MuMuDVB.git && \
cd MuMuDVB && \
autoreconf -i -f && \
./configure --enable-android && \
make && make install
#######
# OPTIONAL: TOOLBOXING
#######
#tool;RUN cd /usr/local/src && \
#tool; git clone git://git.videolan.org/bitstream.git && \
#tool; cd bitstream && \
#tool; make all && make install
#tool;
#tool;RUN cd /usr/local/src && \
#tool; dnf install -y libev-devel && \
#tool; git clone https://code.videolan.org/videolan/dvblast.git && \
#tool; cd dvblast && \
#tool; make all && make install
#tool;
#tool;RUN cd /usr/local/src && \
#tool; yum install -y wget bzip2 && \
#tool; wget http://wirbel.htpc-forum.de/w_scan/w_scan-20170107.tar.bz2 && \
#tool; tar -jxf w_scan-20170107.tar.bz2 && \
#tool; cd w_scan-20170107/ && \
#tool; ./configure && make && make install
#tool;
#tool;RUN cd /usr/local/src && \
#tool; git clone https://github.com/stefantalpalaru/w_scan2.git && \
#tool; cd w_scan2 && \
#tool; autoreconf -i -f && \
#tool; ./configure && make && make install
#tool;
#tool;RUN cd /usr/local/src && \
#tool; yum install -y wget && \
#tool; wget http://udpxy.com/download/udpxy/udpxy-src.tar.gz && \
#tool; tar -zxf udpxy-src.tar.gz && \
#tool; cd udpxy-*/ && \
#tool; make && make install
#tool;
#tool;RUN cd /usr/local/src && \
#tool; yum install -y xz wget && \
#tool; wget ftp://ftp.videolan.org/pub/videolan/miniSAPserver/0.3.8/minisapserver-0.3.8.tar.xz && \
#tool; tar -Jxf minisapserver-0.3.8.tar.xz && \
#tool; cd minisapserver-*/ && \
#tool; ./configure && make && make install
#tool;
#tool;RUN cd /usr/local/src && \
#tool; yum install -y wget && \
#tool; wget https://dl.bintray.com/tvheadend/fedora/bintray-tvheadend-fedora-4.2-stable.repo
###
# OPTIONAL: START OVER AND ONLY RE-INSTALL
###
FROM fedora:28
RUN echo "############################# RUNTIME IMAGE #################################"
# copy the whole /usr/local from the previous compiler-image (note the --from)
COPY --from=compiler_build /usr/local /usr/local
# install runtime libraries
#scam;RUN dnf install -y openssl-devel pcsc-lite libusb
#tool;RUN dnf install -y v4l-utils libev
#tool;RUN mv /usr/local/src/bintray-tvheadend-fedora-4.2-stable.repo /etc/yum.repos.d
#tool;RUN dnf search tvheadend # experimental
# unfortunately, some make's need gcc anyway :(
RUN dnf install -y make gcc gcc-c++ cpp glibc-devel glibc-headers kernel-headers
# re-install all the stuff from before
RUN test -e /usr/local/src/dvb-apps && cd /usr/local/src/dvb-apps && make install && ldconfig || exit 0
RUN test -e /usr/local/src/libdvbcsa && cd /usr/local/src/libdvbcsa && make install && ldconfig || exit 0
RUN cd /usr/local/src/MuMuDVB && make install && mumudvb -v
RUN test -e /usr/local/src/tsdecrypt && cd /usr/local/src/tsdecrypt && make install || exit 0
RUN test -e /usr/local/src/bitstream && cd /usr/local/src/bitstream && make install || exit 0
RUN test -e /usr/local/src/dvblast && cd /usr/local/src/dvblast && make install || exit 0
RUN test -e /usr/local/src/w_scan-20170107 && cd /usr/local/src/w_scan-20170107 && make install || exit 0
RUN test -e /usr/local/src/w_scan2 && cd /usr/local/src/w_scan2 && make install || exit 0
RUN test -e /usr/local/src/udpxy-*/ && cd /usr/local/src/udpxy-*/ && make install || exit 0
RUN test -e /usr/local/src/minisapserver-*/ && cd /usr/local/src/minisapserver-*/ && make install || exit 0
# remove gcc again
RUN dnf remove -y make gcc gcc-c++ cpp glibc-devel glibc-headers kernel-headers
RUN echo "############################# FINAL STEPS #################################"
# add a runtime user
RUN useradd -c "simple user" -g users -G audio,video,cdrom,dialout,lp,tty,games user
# include this very file into the image
COPY Dockerfile /
# use this user as default user
USER user
# assume persistent storage
VOLUME /tmp
# assume exposed ports
EXPOSE 8500:8500
# assume standard runtime executable
CMD ["/bin/bash"]
###
# RECOMMENDED: HOW TO BUILD AND TEST
###
# build mumudvb plain:
# cat Dockerfile.template > Dockerfile; time docker build -t my_mumudvb_simple .
# enable cam/scam support:
# sed -r 's_^#(cam|scam);__g' Dockerfile.template > Dockerfile; time docker build -t my_mumudvb_cam .
# enable tool but not scam support:
# sed -r 's_^#(tool);__g' Dockerfile.template > Dockerfile; time docker build -t my_mumudvb_tool .
# enable all support:
# sed -r 's_^#(cam|scam|tool);__g' Dockerfile.template > Dockerfile; time docker build -t my_mumudvb_full .
# simpe compare and test
# $ docker run -it --rm my_mumudvb_simple /bin/bash
# $ docker run -it --rm my_mumudvb_full /usr/local/bin/w_scan
# $ docker run -it --rm my_mumudvb_cam /usr/local/bin/mumudvb
# $ docker run -it --rm my_mumudvb_tool /usr/local/bin/mumudvb
# run a scan. note the mapped device tree /dev/dvb
# $ docker run -it --rm --device /dev/dvb/ my_mumudvb_full w_scan -f s -s S13E0 -D1c
# run a mumudvb instance. Note the mapped device, filesystem and tcp-port
# $ docker run -it --rm --device /dev/dvb/ --volume ${PWD}/conf:/conf -p 8500:8500 my_mumudvb_cam mumudvb -d -c /conf/test.conf
What can you recommend how to implement and manage this? Re-using the compile-intermediate images could save some space and time, using tags could easy the variant-usage, etc.
What would you suggest?
Look at using ARG and ENV in your Dockerfile. ARG sets values that are available while the image is being built. ENV sets variables available and persist with the image after it is built.
For example, say you needed different settings files based on DEV or PRD versions, you might do this:
ARG=settings_filename
ENV=settings_filename=${settings_filename}
Then call docker to build the image like so:
docker build --build-arg settings_filename="settings.dev"
The ARG line in the Dockerfile sets the value to "settings.dev", but ARG values are not persisted to the image. The ENV line actually persists whatever the ARG value is as an environment variable in the image that is produced.
Are the permutations hierarchical in any fashion? If so, you could create intermediate images and inherit from them. This will have the advantage that the "ancestor" part of the builds will be pre-built, and will not need further build time (except when they change, of course).
If not, you could use your favourite scripting language to build your Dockerfiles. It does not really matter how you do this, what matters is that you automate it. I would suggest using an array to specify, for each named build, what sections it should include. Since this will run quickly, you could always assemble all Dockerfiles, and make that something you do when you do the image builds themselves, so that your specification for a Dockerfile does not come out of sync with the Dockerfiles themselves.
In fact, if you do this, it may be worth not committing your Dockerfiles to version control, since that is one less thing to come out of sync with your scripted definitions.
Addendum
Regarding this remark:
We optionally would like to include some other debugging applications into the same image.
It's worth being careful here about what constitutes a tested image. If you add optional debug tools into an image, then:
if this is not to be deployed to production, then you may end up testing against a version of your app that is not in production. The ideal is to use the same image all the way through your development workflow.
if this is to be deployed to production, it's worth considering whether the attack surface may be increased.
Related
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`
I'm in Julia x Jupyter project and I chose to use jupyter/datascience-notebook Docker Image which contains jupyterlab and Julia environment.
I want to know what package for Julia is pre-installed in jupyter/datascience-notebook and know what extra packages I need to install manually.
I read Dockerfile of datascience-notebook to know what package is installed in the jupyter/datascience-notebook image, but I could not find lines for designating julia packages.
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
ARG OWNER=jupyter
ARG BASE_CONTAINER=$OWNER/scipy-notebook
FROM $BASE_CONTAINER
LABEL maintainer="Jupyter Project <jupyter#googlegroups.com>"
# Fix DL4006
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
USER root
# Julia installation
# Default values can be overridden at build time
# (ARGS are in lower case to distinguish them from ENV)
# Check https://julialang.org/downloads/
ARG julia_version="1.7.1"
# R pre-requisites
RUN apt-get update --yes && \
apt-get install --yes --no-install-recommends \
fonts-dejavu \
gfortran \
gcc && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Julia dependencies
# install Julia packages in /opt/julia instead of ${HOME}
ENV JULIA_DEPOT_PATH=/opt/julia \
JULIA_PKGDIR=/opt/julia \
JULIA_VERSION="${julia_version}"
WORKDIR /tmp
# hadolint ignore=SC2046
RUN set -x && \
julia_arch=$(uname -m) && \
julia_short_arch="${julia_arch}" && \
if [ "${julia_short_arch}" == "x86_64" ]; then \
julia_short_arch="x64"; \
fi; \
julia_installer="julia-${JULIA_VERSION}-linux-${julia_arch}.tar.gz" && \
julia_major_minor=$(echo "${JULIA_VERSION}" | cut -d. -f 1,2) && \
mkdir "/opt/julia-${JULIA_VERSION}" && \
wget -q "https://julialang-s3.julialang.org/bin/linux/${julia_short_arch}/${julia_major_minor}/${julia_installer}" && \
tar xzf "${julia_installer}" -C "/opt/julia-${JULIA_VERSION}" --strip-components=1 && \
rm "${julia_installer}" && \
ln -fs /opt/julia-*/bin/julia /usr/local/bin/julia
# Show Julia where conda libraries are \
RUN mkdir /etc/julia && \
echo "push!(Libdl.DL_LOAD_PATH, \"${CONDA_DIR}/lib\")" >> /etc/julia/juliarc.jl && \
# Create JULIA_PKGDIR \
mkdir "${JULIA_PKGDIR}" && \
chown "${NB_USER}" "${JULIA_PKGDIR}" && \
fix-permissions "${JULIA_PKGDIR}"
USER ${NB_UID}
# R packages including IRKernel which gets installed globally.
# r-e1071: dependency of the caret R package
RUN mamba install --quiet --yes \
'r-base' \
'r-caret' \
'r-crayon' \
'r-devtools' \
'r-e1071' \
'r-forecast' \
'r-hexbin' \
'r-htmltools' \
'r-htmlwidgets' \
'r-irkernel' \
'r-nycflights13' \
'r-randomforest' \
'r-rcurl' \
'r-rodbc' \
'r-rsqlite' \
'r-shiny' \
'rpy2' \
'unixodbc' && \
mamba clean --all -f -y && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"
# These packages are not easy to install under arm
RUN set -x && \
arch=$(uname -m) && \
if [ "${arch}" == "x86_64" ]; then \
mamba install --quiet --yes \
'r-rmarkdown' \
'r-tidymodels' \
'r-tidyverse' && \
mamba clean --all -f -y && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"; \
fi;
# Add Julia packages.
# Install IJulia as jovyan and then move the kernelspec out
# to the system share location. Avoids problems with runtime UID change not
# taking effect properly on the .local folder in the jovyan home dir.
RUN julia -e 'import Pkg; Pkg.update()' && \
julia -e 'import Pkg; Pkg.add("HDF5")' && \
julia -e 'using Pkg; pkg"add IJulia"; pkg"precompile"' && \
# move kernelspec out of home \
mv "${HOME}/.local/share/jupyter/kernels/julia"* "${CONDA_DIR}/share/jupyter/kernels/" && \
chmod -R go+rx "${CONDA_DIR}/share/jupyter" && \
rm -rf "${HOME}/.local" && \
fix-permissions "${JULIA_PKGDIR}" "${CONDA_DIR}/share/jupyter"
WORKDIR "${HOME}"
How can I check out what Julia packages are installed in jupyter/datascience-notebook?
In your code julia -e 'import Pkg; Pkg.add("HDF5")' installs HDF5 package and it is the only package installed beside of IJulia.
If you want to show the list of packages installed in your Julia environment you can do:
julia -e 'using Pkg;Pkg.status()'
Looking at your code this will work correctly as long as you run it with the Julia depot location env variable set to: JULIA_DEPOT_PATH=/opt/julia
The repository jupyter/docker-stacks provides multiple Dockerfiles for Jupyter Notebook images. These Dockerfiles build on each other in the following form:
This Dockerfile is jupyter/base-notebook
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
# Ubuntu 20.04 (focal)
# https://hub.docker.com/_/ubuntu/?tab=tags&name=focal
# OS/ARCH: linux/amd64
ARG ROOT_CONTAINER=ubuntu:focal-20210416#sha256:86ac87f73641c920fb42cc9612d4fb57b5626b56ea2a19b894d0673fd5b4f2e9
ARG BASE_CONTAINER=$ROOT_CONTAINER
FROM $BASE_CONTAINER
LABEL maintainer="Jupyter Project <jupyter#googlegroups.com>"
ARG NB_USER="jovyan"
ARG NB_UID="1000"
ARG NB_GID="100"
# Fix DL4006
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
USER root
# ---- Miniforge installer ----
# Default values can be overridden at build time
# (ARGS are in lower case to distinguish them from ENV)
# Check https://github.com/conda-forge/miniforge/releases
# Conda version
ARG conda_version="4.10.1"
# Miniforge installer patch version
ARG miniforge_patch_number="0"
# Miniforge installer architecture
ARG miniforge_arch="x86_64"
# Package Manager and Python implementation to use (https://github.com/conda-forge/miniforge)
# - conda only: either Miniforge3 to use Python or Miniforge-pypy3 to use PyPy
# - conda + mamba: either Mambaforge to use Python or Mambaforge-pypy3 to use PyPy
ARG miniforge_python="Mambaforge"
# Miniforge archive to install
ARG miniforge_version="${conda_version}-${miniforge_patch_number}"
# Miniforge installer
ARG miniforge_installer="${miniforge_python}-${miniforge_version}-Linux-${miniforge_arch}.sh"
# Miniforge checksum
ARG miniforge_checksum="d4065b376f81b83cfef0c7316f97bb83337e4ae27eb988828363a578226e3a62"
# Install all OS dependencies for notebook server that starts but lacks all
# features (e.g., download as all possible file formats)
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -q update && \
apt-get install -yq --no-install-recommends \
tini \
wget \
ca-certificates \
sudo \
locales \
fonts-liberation \
run-one && \
apt-get clean && rm -rf /var/lib/apt/lists/* && \
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
locale-gen
# Configure environment
ENV CONDA_DIR=/opt/conda \
SHELL=/bin/bash \
NB_USER=$NB_USER \
NB_UID=$NB_UID \
NB_GID=$NB_GID \
LC_ALL=en_US.UTF-8 \
LANG=en_US.UTF-8 \
LANGUAGE=en_US.UTF-8
ENV PATH=$CONDA_DIR/bin:$PATH \
HOME=/home/$NB_USER \
CONDA_VERSION="${conda_version}" \
MINIFORGE_VERSION="${miniforge_version}"
# Copy a script that we will use to correct permissions after running certain commands
COPY fix-permissions /usr/local/bin/fix-permissions
RUN chmod a+rx /usr/local/bin/fix-permissions
# Enable prompt color in the skeleton .bashrc before creating the default NB_USER
# hadolint ignore=SC2016
RUN sed -i 's/^#force_color_prompt=yes/force_color_prompt=yes/' /etc/skel/.bashrc && \
# Add call to conda init script see https://stackoverflow.com/a/58081608/4413446
echo 'eval "$(command conda shell.bash hook 2> /dev/null)"' >> /etc/skel/.bashrc
# Create NB_USER with name jovyan user with UID=1000 and in the 'users' group
# and make sure these dirs are writable by the `users` group.
RUN echo "auth requisite pam_deny.so" >> /etc/pam.d/su && \
sed -i.bak -e 's/^%admin/#%admin/' /etc/sudoers && \
sed -i.bak -e 's/^%sudo/#%sudo/' /etc/sudoers && \
useradd -l -m -s /bin/bash -N -u $NB_UID $NB_USER && \
mkdir -p $CONDA_DIR && \
chown $NB_USER:$NB_GID $CONDA_DIR && \
chmod g+w /etc/passwd && \
fix-permissions $HOME && \
fix-permissions $CONDA_DIR
USER $NB_UID
ARG PYTHON_VERSION=default
# Setup work directory for backward-compatibility
RUN mkdir "/home/$NB_USER/work" && \
fix-permissions "/home/$NB_USER"
# Install conda as jovyan and check the sha256 sum provided on the download site
WORKDIR /tmp
# Prerequisites installation: conda, mamba, pip, tini
RUN wget --quiet "https://github.com/conda-forge/miniforge/releases/download/${miniforge_version}/${miniforge_installer}" && \
echo "${miniforge_checksum} *${miniforge_installer}" | sha256sum --check && \
/bin/bash "${miniforge_installer}" -f -b -p $CONDA_DIR && \
rm "${miniforge_installer}" && \
# Conda configuration see https://conda.io/projects/conda/en/latest/configuration.html
echo "conda ${CONDA_VERSION}" >> $CONDA_DIR/conda-meta/pinned && \
conda config --system --set auto_update_conda false && \
conda config --system --set show_channel_urls true && \
if [ ! $PYTHON_VERSION = 'default' ]; then conda install --yes python=$PYTHON_VERSION; fi && \
conda list python | grep '^python ' | tr -s ' ' | cut -d '.' -f 1,2 | sed 's/$/.*/' >> $CONDA_DIR/conda-meta/pinned && \
conda install --quiet --yes \
"conda=${CONDA_VERSION}" \
'pip' && \
conda update --all --quiet --yes && \
conda clean --all -f -y && \
rm -rf /home/$NB_USER/.cache/yarn && \
fix-permissions $CONDA_DIR && \
fix-permissions /home/$NB_USER
# Install Jupyter Notebook, Lab, and Hub
# Generate a notebook server config
# Cleanup temporary files
# Correct permissions
# Do all this in a single RUN command to avoid duplicating all of the
# files across image layers when the permissions change
RUN conda install --quiet --yes \
'notebook=6.3.0' \
'jupyterhub=1.4.1' \
'jupyterlab=3.0.15' && \
conda clean --all -f -y && \
npm cache clean --force && \
jupyter notebook --generate-config && \
jupyter lab clean && \
rm -rf /home/$NB_USER/.cache/yarn && \
fix-permissions $CONDA_DIR && \
fix-permissions /home/$NB_USER
EXPOSE 8888
# Configure container startup
ENTRYPOINT ["tini", "-g", "--"]
CMD ["start-notebook.sh"]
# Copy local files as late as possible to avoid cache busting
COPY start.sh start-notebook.sh start-singleuser.sh /usr/local/bin/
# Currently need to have both jupyter_notebook_config and jupyter_server_config to support classic and lab
COPY jupyter_notebook_config.py /etc/jupyter/
# Fix permissions on /etc/jupyter as root
USER root
# Prepare upgrade to JupyterLab V3.0 #1205
RUN sed -re "s/c.NotebookApp/c.ServerApp/g" \
/etc/jupyter/jupyter_notebook_config.py > /etc/jupyter/jupyter_server_config.py && \
fix-permissions /etc/jupyter/
# Switch back to jovyan to avoid accidental container runs as root
USER $NB_UID
WORKDIR $HOME
This Dockerfile is jupyter/minimal-notebook
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
ARG BASE_CONTAINER=jupyter/base-notebook
FROM $BASE_CONTAINER
LABEL maintainer="Jupyter Project <jupyter#googlegroups.com>"
USER root
# Install all OS dependencies for fully functional notebook server
RUN apt-get update && apt-get install -yq --no-install-recommends \
build-essential \
vim-tiny \
git \
inkscape \
libsm6 \
libxext-dev \
libxrender1 \
lmodern \
netcat \
# ---- nbconvert dependencies ----
texlive-xetex \
texlive-fonts-recommended \
texlive-plain-generic \
# ----
tzdata \
unzip \
nano-tiny \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Create alternative for nano -> nano-tiny
RUN update-alternatives --install /usr/bin/nano nano /bin/nano-tiny 10
# Switch back to jovyan to avoid accidental container runs as root
USER $NB_UID
This Dockerfile is jupyter/scipy-notebook
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
ARG BASE_CONTAINER=jupyter/minimal-notebook
FROM $BASE_CONTAINER
LABEL maintainer="Jupyter Project <jupyter#googlegroups.com>"
USER root
# ffmpeg for matplotlib anim & dvipng+cm-super for latex labels
RUN apt-get update && \
apt-get install -y --no-install-recommends ffmpeg dvipng cm-super && \
apt-get clean && rm -rf /var/lib/apt/lists/*
USER $NB_UID
# Install Python 3 packages
RUN conda install --quiet --yes \
'beautifulsoup4=4.9.*' \
'conda-forge::blas=*=openblas' \
'bokeh=2.3.*' \
'bottleneck=1.3.*' \
'cloudpickle=1.6.*' \
'cython=0.29.*' \
'dask=2021.4.*' \
'dill=0.3.*' \
'h5py=3.2.*' \
'ipywidgets=7.6.*' \
'ipympl=0.7.*'\
'matplotlib-base=3.4.*' \
'numba=0.53.*' \
'numexpr=2.7.*' \
'pandas=1.2.*' \
'patsy=0.5.*' \
'protobuf=3.15.*' \
'pytables=3.6.*' \
'scikit-image=0.18.*' \
'scikit-learn=0.24.*' \
'scipy=1.6.*' \
'seaborn=0.11.*' \
'sqlalchemy=1.4.*' \
'statsmodels=0.12.*' \
'sympy=1.8.*' \
'vincent=0.4.*' \
'widgetsnbextension=3.5.*'\
'xlrd=2.0.*' && \
conda clean --all -f -y && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"
# Install facets which does not have a pip or conda package at the moment
WORKDIR /tmp
RUN git clone https://github.com/PAIR-code/facets.git && \
jupyter nbextension install facets/facets-dist/ --sys-prefix && \
rm -rf /tmp/facets && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"
# Import matplotlib the first time to build the font cache.
ENV XDG_CACHE_HOME="/home/${NB_USER}/.cache/"
RUN MPLBACKEND=Agg python -c "import matplotlib.pyplot" && \
fix-permissions "/home/${NB_USER}"
USER $NB_UID
WORKDIR $HOME
Finally, this Dockerfile is jupyter/tensorflow-notebook
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
ARG BASE_CONTAINER=jupyter/scipy-notebook
FROM $BASE_CONTAINER
LABEL maintainer="Jupyter Project <jupyter#googlegroups.com>"
# Install Tensorflow
RUN mamba install --quiet --yes \
'tensorflow=2.4.1' && \
conda clean --all -f -y && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"
I built each of these images locally (using BuildKit) with the following command:
docker build --rm --force-rm -t <TAG HERE> <FOLDER NAME HERE>
Here, the final image size of jupyter/tensorflow-notebook is 3.17 GB.
I then combined all the previous Dockerfiles into the following multi-stage build Dockerfile:
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
# Ubuntu 20.04 (focal)
# https://hub.docker.com/_/ubuntu/?tab=tags&name=focal
# OS/ARCH: linux/amd64
ARG ROOT_CONTAINER=ubuntu:focal-20210416#sha256:86ac87f73641c920fb42cc9612d4fb57b5626b56ea2a19b894d0673fd5b4f2e9
ARG BASE_CONTAINER=$ROOT_CONTAINER
FROM $BASE_CONTAINER AS base
LABEL maintainer="Jupyter Project <jupyter#googlegroups.com>"
ARG NB_USER="jovyan"
ARG NB_UID="1000"
ARG NB_GID="100"
# Fix DL4006
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
USER root
# ---- Miniforge installer ----
# Default values can be overridden at build time
# (ARGS are in lower case to distinguish them from ENV)
# Check https://github.com/conda-forge/miniforge/releases
# Conda version
ARG conda_version="4.10.1"
# Miniforge installer patch version
ARG miniforge_patch_number="0"
# Miniforge installer architecture
ARG miniforge_arch="x86_64"
# Package Manager and Python implementation to use (https://github.com/conda-forge/miniforge)
# - conda only: either Miniforge3 to use Python or Miniforge-pypy3 to use PyPy
# - conda + mamba: either Mambaforge to use Python or Mambaforge-pypy3 to use PyPy
ARG miniforge_python="Mambaforge"
# Miniforge archive to install
ARG miniforge_version="${conda_version}-${miniforge_patch_number}"
# Miniforge installer
ARG miniforge_installer="${miniforge_python}-${miniforge_version}-Linux-${miniforge_arch}.sh"
# Miniforge checksum
ARG miniforge_checksum="d4065b376f81b83cfef0c7316f97bb83337e4ae27eb988828363a578226e3a62"
# Install all OS dependencies for notebook server that starts but lacks all
# features (e.g., download as all possible file formats)
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -q update && \
apt-get install -yq --no-install-recommends \
tini \
wget \
ca-certificates \
sudo \
locales \
fonts-liberation \
run-one && \
apt-get clean && rm -rf /var/lib/apt/lists/* && \
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
locale-gen
# Configure environment
ENV CONDA_DIR=/opt/conda \
SHELL=/bin/bash \
NB_USER=$NB_USER \
NB_UID=$NB_UID \
NB_GID=$NB_GID \
LC_ALL=en_US.UTF-8 \
LANG=en_US.UTF-8 \
LANGUAGE=en_US.UTF-8
ENV PATH=$CONDA_DIR/bin:$PATH \
HOME=/home/$NB_USER \
CONDA_VERSION="${conda_version}" \
MINIFORGE_VERSION="${miniforge_version}"
# Copy a script that we will use to correct permissions after running certain commands
COPY fix-permissions /usr/local/bin/fix-permissions
RUN chmod a+rx /usr/local/bin/fix-permissions
# Enable prompt color in the skeleton .bashrc before creating the default NB_USER
# hadolint ignore=SC2016
RUN sed -i 's/^#force_color_prompt=yes/force_color_prompt=yes/' /etc/skel/.bashrc && \
# Add call to conda init script see https://stackoverflow.com/a/58081608/4413446
echo 'eval "$(command conda shell.bash hook 2> /dev/null)"' >> /etc/skel/.bashrc
# Create NB_USER with name jovyan user with UID=1000 and in the 'users' group
# and make sure these dirs are writable by the `users` group.
RUN echo "auth requisite pam_deny.so" >> /etc/pam.d/su && \
sed -i.bak -e 's/^%admin/#%admin/' /etc/sudoers && \
sed -i.bak -e 's/^%sudo/#%sudo/' /etc/sudoers && \
useradd -l -m -s /bin/bash -N -u $NB_UID $NB_USER && \
mkdir -p $CONDA_DIR && \
chown $NB_USER:$NB_GID $CONDA_DIR && \
chmod g+w /etc/passwd && \
fix-permissions $HOME && \
fix-permissions $CONDA_DIR
USER $NB_UID
ARG PYTHON_VERSION=default
# Setup work directory for backward-compatibility
RUN mkdir "/home/$NB_USER/work" && \
fix-permissions "/home/$NB_USER"
# Install conda as jovyan and check the sha256 sum provided on the download site
WORKDIR /tmp
# Prerequisites installation: conda, mamba, pip, tini
RUN wget --quiet "https://github.com/conda-forge/miniforge/releases/download/${miniforge_version}/${miniforge_installer}" && \
echo "${miniforge_checksum} *${miniforge_installer}" | sha256sum --check && \
/bin/bash "${miniforge_installer}" -f -b -p $CONDA_DIR && \
rm "${miniforge_installer}" && \
# Conda configuration see https://conda.io/projects/conda/en/latest/configuration.html
echo "conda ${CONDA_VERSION}" >> $CONDA_DIR/conda-meta/pinned && \
conda config --system --set auto_update_conda false && \
conda config --system --set show_channel_urls true && \
if [ ! $PYTHON_VERSION = 'default' ]; then conda install --yes python=$PYTHON_VERSION; fi && \
conda list python | grep '^python ' | tr -s ' ' | cut -d '.' -f 1,2 | sed 's/$/.*/' >> $CONDA_DIR/conda-meta/pinned && \
conda install --quiet --yes \
"conda=${CONDA_VERSION}" \
'pip' && \
conda update --all --quiet --yes && \
conda clean --all -f -y && \
rm -rf /home/$NB_USER/.cache/yarn && \
fix-permissions $CONDA_DIR && \
fix-permissions /home/$NB_USER
# Install Jupyter Notebook, Lab, and Hub
# Generate a notebook server config
# Cleanup temporary files
# Correct permissions
# Do all this in a single RUN command to avoid duplicating all of the
# files across image layers when the permissions change
RUN conda install --quiet --yes \
'notebook=6.3.0' \
'jupyterhub=1.4.1' \
'jupyterlab=3.0.15' && \
conda clean --all -f -y && \
npm cache clean --force && \
jupyter notebook --generate-config && \
jupyter lab clean && \
rm -rf /home/$NB_USER/.cache/yarn && \
fix-permissions $CONDA_DIR && \
fix-permissions /home/$NB_USER
EXPOSE 8888
# Configure container startup
ENTRYPOINT ["tini", "-g", "--"]
CMD ["start-notebook.sh"]
# Copy local files as late as possible to avoid cache busting
COPY start.sh start-notebook.sh start-singleuser.sh /usr/local/bin/
# Currently need to have both jupyter_notebook_config and jupyter_server_config to support classic and lab
COPY jupyter_notebook_config.py /etc/jupyter/
# Fix permissions on /etc/jupyter as root
USER root
# Prepare upgrade to JupyterLab V3.0 #1205
RUN sed -re "s/c.NotebookApp/c.ServerApp/g" \
/etc/jupyter/jupyter_notebook_config.py > /etc/jupyter/jupyter_server_config.py && \
fix-permissions /etc/jupyter/
# Switch back to jovyan to avoid accidental container runs as root
USER $NB_UID
WORKDIR $HOME
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
ARG BASE_CONTAINER=jupyter/base-notebook
FROM base AS minimal
LABEL maintainer="Jupyter Project <jupyter#googlegroups.com>"
USER root
# Install all OS dependencies for fully functional notebook server
RUN apt-get update && apt-get install -yq --no-install-recommends \
build-essential \
vim-tiny \
git \
inkscape \
libsm6 \
libxext-dev \
libxrender1 \
lmodern \
netcat \
# ---- nbconvert dependencies ----
texlive-xetex \
texlive-fonts-recommended \
texlive-plain-generic \
# ----
tzdata \
unzip \
nano-tiny \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Create alternative for nano -> nano-tiny
RUN update-alternatives --install /usr/bin/nano nano /bin/nano-tiny 10
# Switch back to jovyan to avoid accidental container runs as root
USER $NB_UID
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
ARG BASE_CONTAINER=jupyter/minimal-notebook
FROM minimal AS scipy
LABEL maintainer="Jupyter Project <jupyter#googlegroups.com>"
USER root
# ffmpeg for matplotlib anim & dvipng+cm-super for latex labels
RUN apt-get update && \
apt-get install -y --no-install-recommends ffmpeg dvipng cm-super && \
apt-get clean && rm -rf /var/lib/apt/lists/*
USER $NB_UID
# Install Python 3 packages
RUN conda install --quiet --yes \
'beautifulsoup4=4.9.*' \
'conda-forge::blas=*=openblas' \
'bokeh=2.3.*' \
'bottleneck=1.3.*' \
'cloudpickle=1.6.*' \
'cython=0.29.*' \
'dask=2021.4.*' \
'dill=0.3.*' \
'h5py=3.2.*' \
'ipywidgets=7.6.*' \
'ipympl=0.7.*'\
'matplotlib-base=3.4.*' \
'numba=0.53.*' \
'numexpr=2.7.*' \
'pandas=1.2.*' \
'patsy=0.5.*' \
'protobuf=3.15.*' \
'pytables=3.6.*' \
'scikit-image=0.18.*' \
'scikit-learn=0.24.*' \
'scipy=1.6.*' \
'seaborn=0.11.*' \
'sqlalchemy=1.4.*' \
'statsmodels=0.12.*' \
'sympy=1.8.*' \
'vincent=0.4.*' \
'widgetsnbextension=3.5.*'\
'xlrd=2.0.*' && \
conda clean --all -f -y && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"
# Install facets which does not have a pip or conda package at the moment
WORKDIR /tmp
RUN git clone https://github.com/PAIR-code/facets.git && \
jupyter nbextension install facets/facets-dist/ --sys-prefix && \
rm -rf /tmp/facets && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"
# Import matplotlib the first time to build the font cache.
ENV XDG_CACHE_HOME="/home/${NB_USER}/.cache/"
RUN MPLBACKEND=Agg python -c "import matplotlib.pyplot" && \
fix-permissions "/home/${NB_USER}"
USER $NB_UID
WORKDIR $HOME
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
ARG BASE_CONTAINER=jupyter/scipy-notebook
FROM scipy AS tensorflow
LABEL maintainer="Jupyter Project <jupyter#googlegroups.com>"
# Install Tensorflow
RUN mamba install --quiet --yes \
'tensorflow=2.4.1' && \
conda clean --all -f -y && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"
The size of this image is 14.61 GB, 11 GB greater than the split Dockerfiles build.
What's the reason behind this drastic increase in size?
Sorry, this is my first time using docker so there may be chances that I'm using the wrong term. Basically, I need to use this image as the base of our project, however, when I try to build our project using docker-compose it takes quite a long time build which I suspect is because of the file size of the image. Is there anything I can do to reduce the file size down to 500MB? Here is what I have in the image's docker file.
FROM php:7.2-apache-buster
ENV V8_VERSION=7.4.288.21
RUN apt-get update -y --fix-missing && apt-get upgrade -y;
# Install v8js (see https://github.com/phpv8/v8js/blob/php7/README.Linux.md)
RUN apt-get install -y --no-install-recommends \
libtinfo5 libtinfo-dev \
build-essential \
curl \
git \
libglib2.0-dev \
libxml2 \
python \
patchelf \
&& cd /tmp \
\
&& git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git --progress --verbose \
&& export PATH="$PATH:/tmp/depot_tools" \
\
&& fetch v8 \
&& cd v8 \
&& git checkout $V8_VERSION \
&& gclient sync \
\
&& tools/dev/v8gen.py -vv x64.release -- is_component_build=true use_custom_libcxx=false
RUN export PATH="$PATH:/tmp/depot_tools" \
&& cd /tmp/v8 \
&& ninja -C out.gn/x64.release/ \
&& mkdir -p /opt/v8/lib && mkdir -p /opt/v8/include \
&& cp out.gn/x64.release/lib*.so out.gn/x64.release/*_blob.bin out.gn/x64.release/icudtl.dat /opt/v8/lib/ \
&& cp -R include/* /opt/v8/include/ \
&& apt-get install patchelf \
&& for A in /opt/v8/lib/*.so; do patchelf --set-rpath '$ORIGIN' $A;done
# Install php-v8js
RUN cd /tmp \
&& git clone https://github.com/phpv8/v8js.git \
&& cd v8js \
&& phpize \
&& ./configure --with-v8js=/opt/v8 LDFLAGS="-lstdc++" \
&& make \
&& make test \
&& make install
RUN docker-php-ext-enable v8js
As #david-maze pointed me to right direction which is to use multi-stage build I managed to reduce the file size from almost 5GB down to 470MB by tracing all the files I need to copy to another build. Here is what I got
FROM php:7.2-apache-buster
COPY --from=BASE_PHP /opt /opt
COPY --from=BASE_PHP /usr/local/etc/php/conf.d/docker-php-ext-v8js.ini /usr/local/etc/php/conf.d/
COPY --from=BASE_PHP /usr/local/lib/php/extensions/no-debug-non-zts-20170718 /usr/local/lib/php/extensions/no-debug-non-zts-20170718
Thank you so much
I am trying to build a lean alpine docker container for unit testing Lua in Google Cloud Build.
It runs fine, but takes about 30 - 50 seconds to build. When I run busted and luacheck, it only takes a few seconds for each. Any thoughts on how I could optimize this build process?
I was using wget and then switched to git. I added curl and unzip since luarocks expects it and openssl for one of luacheck's dependencies. Are there different dependencies I could/should use?
FROM alpine
ENV LUA_VERSION 5.1
RUN apk update
RUN apk add lua${LUA_VERSION}
RUN apk add lua${LUA_VERSION}-dev
RUN apk add bash build-base curl git openssl unzip
RUN cd /tmp && \
git clone https://github.com/keplerproject/luarocks.git && \
cd luarocks && \
sh ./configure && \
make build install && \
cd && \
rm -rf /tmp/luarocks
RUN luarocks install busted
RUN luarocks install luacheck
RUN luarocks install luacov
You can try this
Dockerfile
FROM alpine:3.12
# Set environment
ENV LUA_VERSION=5.1.5 \
LUAROCKS_VERSION=3.4.0
# Install dependency packages
RUN set -xe && \
apk add --no-cache --virtual .build-deps \
curl \
gcc \
g++ \
libc-dev \
make \
readline-dev \
&& \
apk add --no-cache \
readline \
&& \
# Install Lua
wget http://www.lua.org/ftp/lua-${LUA_VERSION}.tar.gz && \
tar zxf lua-${LUA_VERSION}.tar.gz && rm -f lua-${LUA_VERSION}.tar.gz && \
cd lua-${LUA_VERSION} && \
make -j $(getconf _NPROCESSORS_ONLN) linux && make install && \
cd / && rm -rf lua-${LUA_VERSION} && \
# Install LuaRocks
wget https://luarocks.org/releases/luarocks-${LUAROCKS_VERSION}.tar.gz && \
tar zxf luarocks-${LUAROCKS_VERSION}.tar.gz && rm -f luarocks-${LUAROCKS_VERSION}.tar.gz && \
cd luarocks-${LUAROCKS_VERSION} && \
./configure && \
make -j $(getconf _NPROCESSORS_ONLN) build && make install && \
cd / && rm -rf luarocks-${LUAROCKS_VERSION} && \
# Remove all build deps
apk del .build-deps && \
# Test
lua -v && luarocks
COPY docker-entrypoint.sh /usr/local/bin
docker-entrypoint.sh
#!/bin/sh
set -e
buildDepsApk="
curl
libc-dev
gcc
wget
"
pm='unknown'
if [ -e /lib/apk/db/installed ]; then
pm='apk'
fi
if [ "$pm" = 'apk' ]; then
apk add --no-cache ${buildDepsApk}
fi
luarocks install $#
if [ "$pm" = 'apk' ]; then
apk del ${buildDepsApk}
fi
You don't have to build luarocks. You can just install the package using,
RUN apk add luarocks