Commit 94a5ad99 authored by Vincent Delbar's avatar Vincent Delbar
Browse files

ENH: Docker base image with system lib only

parent c7866b48
......@@ -29,7 +29,7 @@ echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker Engine
# Install latest Docker Community Edition
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
......@@ -86,7 +86,7 @@ docker exec --user root moringa apt-get upgrade -y
docker inspect moringa # See full container info dump
docker logs moringa # See command logs and outputs
docker stats moringa # Real time container statistics
docker {pause/unpause} moringa # Pause all container's processes
docker {pause,unpause} moringa # Freeze container
# Don't forget to kill a background container when you're done
docker stop moringa
......@@ -102,30 +102,32 @@ cd moringa
docker login gitlab-registry.irstea.fr
# OTB base image, example with arg OTB_VERSION=7.2 (default value)
docker build --build-arg OTB_VERSION=7.2 -f docker/base-otb/Dockerfile \
-t gitlab-registry.irstea.fr/raffaele.gaetano/moringa:base-otb-7.2 .
docker push gitlab-registry.irstea.fr/raffaele.gaetano/moringa:base-otb-7.2
# OTB base image, example with tag 7.2.0 (default value is release-7.2)
docker build --build-arg OTB_BRANCH=7.2.0 -f docker/base-otb/Dockerfile \
-t gitlab-registry.irstea.fr/raffaele.gaetano/moringa:base-focal-otb72 .
docker push gitlab-registry.irstea.fr/raffaele.gaetano/moringa:base-focal-otb72
# Tag 'base-otb' == default base image for the moringa build
docker tag gitlab-registry.irstea.fr/raffaele.gaetano/moringa:base-otb-7.2 \
docker tag gitlab-registry.irstea.fr/raffaele.gaetano/moringa:base-focal-otb72 \
gitlab-registry.irstea.fr/raffaele.gaetano/moringa:base-otb
docker push gitlab-registry.irstea.fr/raffaele.gaetano/moringa:base-otb
# MORINGA build from the default 'base-otb' image
# You don't need to rebuild OTB if you just want to update moringa files using current branch / local commits
#git checkout custom_branch
docker build -f docker/moringa/Dockerfile -t gitlab-registry.irstea.fr/raffaele.gaetano/moringa .
docker push gitlab-registry.irstea.fr/raffaele.gaetano/moringa:latest
# MORINGA build from custom image
docker build -f docker/moringa/Dockerfile \
--build-arg BASE_IMG=gitlab-registry.irstea.fr/raffaele.gaetano/moringa:base-otb-dev \
-t gitlab-registry.irstea.fr/raffaele.gaetano/moringa .
# Build with custom ubuntu base image
docker build --build-arg BASE_IMG=ubuntu:18.04 -f docker/base-otb/Dockerfile \
-t gitlab-registry.irstea.fr/raffaele.gaetano/moringa:base-bionic-otb72 .
docker push gitlab-registry.irstea.fr/raffaele.gaetano/moringa:base-bionic-otb72
```
### Fix volume ownership issue (required if host's UID > 1000)
When mounting a volume, you may experience errors while trying to write files from within the container.
Since the default user (ubuntu) is UID 1000, you won't be able to write files into your volume which is mounted with the same UID than your linux host user (may be UID 1001 or more).
Since the default user (ubuntu) is UID 1000, you won't be able to write files into your volume
which is mounted with the same UID than your linux host user (may be UID 1001 or more).
In order to address this, you need to edit the container's user UID and GID to match the right numerical value.
This will only persist in a named container, it is required every time you're creating a new one.
......@@ -137,12 +139,13 @@ docker create --interactive --tty --volume /home/$USER:/home/ubuntu/data \
# Start a background container process (in order to exec root commands, because default user isn't sudoer)
docker start moringa
# Exec required commands with user root (here with host's user ID, or you'll need to replace $UID and $GID with desired values)
# Exec required commands with user root (here with host's ID, replace $UID and $GID with desired values)
docker exec --user root moringa usermod ubuntu -u $UID
docker exec --user root moringa groupmod ubuntu -g $GID
# Force reset ownership with updated UID and GID.
# Make sure to double check what you're doing since recursive chown will apply to your volume in /home/ubuntu/data)
# Force reset ownership with updated UID and GID. Make sure to double check that
docker exec moringa id
# Because recursive chown will apply to your volume in /home/ubuntu/data)
docker exec --user root moringa chown -R ubuntu:ubuntu /home/ubuntu
# Stop the background container and start a new interactive shell
......@@ -150,10 +153,10 @@ docker stop moringa
docker start -i moringa
```
```bash
# Check if ownership is as exepected
# Check if ownership is right
id
ls -Alh /home/ubuntu
ls -Alh /home/ubuntu/data
# Test writing a file
touch /home/ubuntu/data/test.txt
```
\ No newline at end of file
```
FROM ubuntu:20.04
ARG BASE_IMG=ubuntu:20.04
# Base image can be either focal (20.04) or bionic (18.04) and descendants
FROM $BASE_IMG
LABEL description="A base image with OTB and remote modules for the MORINGA processing chain, CIRAD/UMR TETIS"
# Build env
WORKDIR /tmp
ARG OTB_VERSION=7.2
ARG OTB_BRANCH=release-7.2
# System dependencies
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install -y --no-install-recommends \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get install -y --no-install-recommends \
bzip2 \
cmake \
curl \
......@@ -31,16 +33,66 @@ RUN apt-get update \
vim \
wget \
zip \
# OTB CLI requirements
&& apt-get install -y --no-install-recommends \
bison \
gdal-bin \
python3-gdal \
libboost-date-time-dev \
libboost-filesystem-dev \
libboost-graph-dev \
libboost-program-options-dev \
libboost-system-dev \
libboost-thread-dev \
libcurl4-gnutls-dev \
libexpat1-dev \
libfftw3-dev \
libgdal-dev \
libgeotiff-dev \
libgsl-dev \
libinsighttoolkit4-dev \
libkml-dev \
libmuparser-dev \
libmuparserx-dev \
libopencv-core-dev \
libopencv-ml-dev \
libopenthreads-dev \
libossim-dev \
libpng-dev \
libsvm-dev \
libtinyxml-dev \
zlib1g-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# SuperBuild OTB with remote modules, no GUI, no system libs
RUN git clone -b release-$OTB_VERSION "https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb.git" \
# SuperBuild OTB with remote modules, no GUI
RUN git clone -b $OTB_BRANCH "https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb.git" \
&& mkdir /tmp/SuperBuild-archives /tmp/build /opt/otb \
&& cd /tmp/build \
# Build dependencies
# Build deps (trying only system lib, SuperBuild is required only SHARK)
&& cmake /tmp/otb/SuperBuild \
-DCMAKE_BUILD_TYPE='Release' \
-DUSE_SYSTEM_BOOST=ON \
-DUSE_SYSTEM_CURL=ON \
-DUSE_SYSTEM_EXPAT=ON \
-DUSE_SYSTEM_FFTW=ON \
-DUSE_SYSTEM_FREETYPE=ON \
-DUSE_SYSTEM_GDAL=ON \
-DUSE_SYSTEM_GEOS=ON \
-DUSE_SYSTEM_GEOTIFF=ON \
-DUSE_SYSTEM_GSL=ON \
-DUSE_SYSTEM_ITK=ON \
-DUSE_SYSTEM_LIBKML=ON \
-DUSE_SYSTEM_LIBSVM=ON \
-DUSE_SYSTEM_MUPARSER=ON \
-DUSE_SYSTEM_MUPARSERX=ON \
-DUSE_SYSTEM_OPENCV=ON \
-DUSE_SYSTEM_OPENTHREADS=ON \
-DUSE_SYSTEM_OSSIM=ON \
-DUSE_SYSTEM_PNG=ON \
-DUSE_SYSTEM_TINYXML=ON \
-DUSE_SYSTEM_ZLIB=ON \
-DUSE_SYSTEM_SWIG=ON \
-DOTB_USE_QT=OFF \
-DOTB_USE_OPENGL=OFF \
-DOTB_USE_GLUT=OFF \
......@@ -66,7 +118,7 @@ RUN git clone -b release-$OTB_VERSION "https://gitlab.orfeo-toolbox.org/orfeotoo
-DModule_OTBTemporalGapFilling=ON \
-DModule_S1TilingSupportApplications=ON \
-DOTB_WRAP_PYTHON=ON \
-DPYTHON_EXECUTABLE=/usr/bin/python3.8 \
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
-DCMAKE_INSTALL_PREFIX=/opt/otb \
&& cd /tmp/build \
&& make -j8 \
......
ARG BASE_IMG=gitlab-registry.irstea.fr/raffaele.gaetano/moringa:base-otb
ARG BASE_IMG=gitlab-registry.irstea.fr/raffaele.gaetano/moringa:base
FROM $BASE_IMG
LABEL description="A container for the MORINGA processing chain, CIRAD/UMR TETIS"
# Compile obiatools library
RUN git clone "https://gitlab.irstea.fr/raffaele.gaetano/obiatools.git" && cd obiatools/Release \
&& sed -i 's/$HOME\/moringa/\/usr\/local\/lib\/python3.8\/dist-packages/g' configure.sh \
&& sed -i 's/python3.6/python3.8/g' configure.sh \
&& mkdir /usr/local/lib/python3.8/dist-packages/sitsproc_c_modules \
&& touch /usr/local/lib/python3.8/dist-packages/sitsproc_c_modules/__init__.py \
&& bash -c "source configure.sh && make" && cd ../.. && rm -rf obiatools
# Other python deps: rios, fmask
# PIP dependencies : rios, fmask
RUN pip3 install rios.core \
&& wget -q "https://github.com/ubarsc/python-fmask/releases/download/pythonfmask-0.5.5/python-fmask-0.5.5.tar.gz" \
&& tar -xzf python-fmask-0.5.5.tar.gz && cd python-fmask-0.5.5 \
&& python3 setup.py install && cd .. && rm -rf python-fmask-*
ENV RIOS_DFLT_DRIVER="GTiff"
# Make python3 the default python command
RUN ln -s /usr/bin/python3 /usr/bin/python
# Compile obiatools library
RUN export PY_MINOR=$(python3 -c "import sys; print(sys.version_info.minor)") \
&& git clone "https://gitlab.irstea.fr/raffaele.gaetano/obiatools.git" && cd obiatools/Release \
&& sed -i "s/\$HOME\/moringa/\/usr\/local\/lib\/python3.$PY_MINOR\/dist-packages/g" configure.sh \
&& sed -i "s/python3.6/python3.$PY_MINOR/g" configure.sh \
&& mkdir "/usr/local/lib/python3.$PY_MINOR/dist-packages/sitsproc_c_modules" \
&& touch "/usr/local/lib/python3.$PY_MINOR/dist-packages/sitsproc_c_modules/__init__.py" \
&& bash -c "source configure.sh && make -j4" && cd ../.. && rm -rf obiatools
# Default user and directory when running a container, is active now
RUN useradd -s /bin/bash -m ubuntu
......@@ -32,6 +31,9 @@ RUN git clone -b python3 "https://github.com/olivierhagolle/theia_download.git"
RUN wget -q "http://step.esa.int/thirdparties/sen2cor/2.8.0/Sen2Cor-02.08.00-Linux64.run" \
&& bash Sen2Cor-02.08.00-Linux64.run && rm Sen2Cor-02.08.00-Linux64.run -f
# Copy full repository
# Install the MORINGA
RUN mkdir moringa
# Copy files without .git
COPY --chown=ubuntu . /home/ubuntu/moringa
# OR
#RUN git clone --single-branch -b develop https://gitlab.irstea.fr/raffaele.gaetano/moringa.git
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment