Skip to main content
1 of 2

Multi stage Dockerfile for eccode compilation

I wrote a Dockerfile to install ecCodes for use in a python environment using cfgrib and xarray.

The tarball can be found on the Eccode releases page

Dockerfile

# syntax=docker/dockerfile:1
# ECCODE COMPILE
FROM python:3.10.4 as compiler
# /path/to/where/you/install/eccodes
ENV ECCODES_DIR=/usr/src/eccodes
# the zip file for eccodes
COPY ./eccodes-2.24.2-Source.tar.gz ./eccodes-2.24.2-Source.tar.gz

RUN apt-get update -y
# compiler tools
RUN apt-get install -y --no-install-recommends \
    cmake \
    gfortran \
    build-essential

# unzip 
RUN tar -xzf eccodes-2.24.2-Source.tar.gz 
# prepare the build folders
RUN mkdir $ECCODES_DIR build && cd build
# 
RUN cmake ../eccodes-2.24.2-Source -DCMAKE_INSTALL_PREFIX=$ECCODES_DIR -DENABLE_JPG=ON

RUN make && ctest && make install


# PYTHON BUILD
FROM python:3.10.4 as builder

ENV VIRTUAL_ENV=/opt/venv

COPY ./requirements.txt ./requirements.txt 
# create the virtual env
RUN python3 -m venv $VIRTUAL_ENV 
# upgrade pip
RUN python3 -m pip install --upgrade pip
# install the requirements
RUN pip install -r requirements.txt


# FINAL
FROM python:3.10.4

COPY --from=compiler $ECCODES_DIR $ECCODES_DIR

ENV ECCODES_DIR=$ECCODES_DIR

COPY --from=builder $VIRTUAL_ENV $VIRTUAL_ENV

ENV PATH="$VIRTUAL_ENV/bin:$PATH"

RUN python -m cfgrib selfcheck

requirements.txt

attrs==21.4.0
cffi==1.15.0
cfgrib==0.9.10.1
click==8.1.3
eccodes==1.4.2
findlibs==0.0.2
numpy==1.22.4
packaging==21.3
pandas==1.4.2
pycparser==2.21
pyparsing==3.0.9
python-dateutil==2.8.2
pytz==2022.1
six==1.16.0
xarray==2022.3.0