../_images/logo.png

YumaPro Docker Developer Guide

Install Docker

Installation of the Docker environment is required on your host system to enable the use of YumaPro Docker images. The links below, based on the operating system you will be using, provide Docker installation instructions. There are many other examples that can be found on the Internet:

Build Image

To build the Docker image for YumaPro SDK, follow these steps:

  1. Create a 'Dockerfile' with the following content:

# Base image with specified Ubuntu version
ARG UBUNTU_VERSION="22.04"
FROM ubuntu:$UBUNTU_VERSION

# Set default values for ARG variables if not set during build
ARG LOG_DIR="docker-logs"
ARG SUDO_USER="user-1"
ARG SUDO_PASSWORD="password-1"
ARG YUMAPRO_SDK_SOURCE
ARG YUMAPRO_SDK_DEST="/yumapro-sdk"

# Check if YUMAPRO_SDK_SOURCE is provided
RUN if [ -z "$YUMAPRO_SDK_SOURCE" ]; then \
        echo "Error: YUMAPRO_SDK_SOURCE is not provided."; \
        echo "Please provide the path to the deb file or source code directory using --build-arg YUMAPRO_SDK_SOURCE=<path>"; \
        exit 1; \
    fi

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive

# Update package lists and install necessary packages
RUN apt-get update && apt-get install -y --no-install-recommends \
    sudo \
    wget \
    cmake \
    build-essential \
    libxml2-dev \
    libcbor-dev \
    openssh-server \
    libssl-dev \
    libcurl4-gnutls-dev \
    libfcgi-dev \
    libssh2-1-dev \
    libncurses5-dev \
    zlib1g-dev \
    libzmq3-dev \
    sshpass \
    libapache2-mod-fcgid \
    curl \
    net-tools \
    nano \
    apache2 \
    systemd \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Create a user '${SUDO_USER}' with password '${SUDO_PASSWORD}' and add to sudo group
RUN echo 'root:root' | chpasswd && \
    useradd -m $SUDO_USER && \
    echo "$SUDO_USER:$SUDO_PASSWORD" | chpasswd && \
    adduser $SUDO_USER sudo

# Copy the source code or YUMAPRO SDK .deb file into the Docker build context based on provided arguments
COPY $YUMAPRO_SDK_SOURCE $YUMAPRO_SDK_DEST/

# Install YumaPro SDK from source or .deb file
RUN cd $YUMAPRO_SDK_DEST/ && \
    if [ -f "$(basename "$YUMAPRO_SDK_SOURCE")" ] && [ "${YUMAPRO_SDK_SOURCE##*.}" = "deb" ]; then \
        dpkg -i $(basename $YUMAPRO_SDK_SOURCE); \
    else \
        make EVERYTHING=1 USE_WERROR=1 DEBUG=1 && \
        make install EVERYTHING=1 USE_WERROR=1 DEBUG=1; \
    fi && \
    cd /

# Configure SSH
RUN sed -i 's/#Port 22/Port 22\nPort 830/' /etc/ssh/sshd_config && \
    echo "Subsystem netconf /usr/sbin/netconf-subsystem-pro" >> /etc/ssh/sshd_config && \
    /etc/init.d/ssh start && \
    mkdir -p /home/$SUDO_USER/.ssh && \
    ssh-keygen -t ed25519 -f /home/$SUDO_USER/.ssh/id_rsa -N "" && \
    mkdir -p /root/.ssh && \
    ssh-keyscan -t ed25519 localhost >> /root/.ssh/known_hosts && \
    cat /home/$SUDO_USER/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys && \
    chmod 700 /home/$SUDO_USER/.ssh && \
    chmod 600 /home/$SUDO_USER/.ssh/*

# Configure RESTCONF
RUN if [ -f "$YUMAPRO_SDK_DEST/$(basename $YUMAPRO_SDK_SOURCE)" ] && [ "${YUMAPRO_SDK_SOURCE##*.}" = "deb" ]; then \
        mkdir -p /var/www/yang-api/ && \
        mv /usr/sbin/restconf /var/www/yang-api/ && \
        chmod 775 /var/www/yang-api/restconf && \
        chown www-data:www-data /var/www/yang-api/restconf; \
    fi && \
    a2enmod fcgid status headers && \
    echo "ServerName localhost" >> /etc/apache2/apache2.conf && \
    cp /usr/share/yumapro/util/restconf.conf /etc/apache2/sites-available/ && \
    a2ensite restconf.conf && \
    rm /etc/apache2/sites-available/000-default.conf

# Set temp env var
ENV DOCKER_PARAMS_U=$SUDO_USER
ENV DOCKER_PARAMS_P=$SUDO_PASSWORD
ENV DOCKER_PARAMS_L=$LOG_DIR

# Switch to the non-root user
USER $SUDO_USER

# Set working directory
WORKDIR /home/$SUDO_USER/

# Create the directory to store logs
RUN mkdir -p $LOG_DIR

# Expose SSH and NETCONF ports
EXPOSE 22 830

# Running commands on container startup
CMD echo $DOCKER_PARAMS_P | sudo -S service ssh restart > /dev/null 2>&1 && \
    sudo service apache2 restart > /dev/null 2>&1 && \
    netconfd-pro --version && \
    sudo -b netconfd-pro --fileloc-fhs=true --log-level=debug4 --log=$DOCKER_PARAMS_L/netconfd-docker.log --access-control=off --with-yuma-system=true && \
    echo "Starting netconfd-pro server in the background with basic parameters.." && \
    echo "Refer to $DOCKER_PARAMS_L/netconfd-docker.log file for logging information." && \
    # Remove all docker_params_*
    unset $(env | grep 'DOCKER_PARAMS' | awk -F= '{print $1}') && \
    /bin/bash
  1. Copy the YumaPro SDK deb file or source code directory into the directory where you run the docker build.

Note

Ensure the YumaPro SDK deb file or source code directory is copied into the directory where you run the docker build and then Provide the path of those resources within your Dockerfile before building the image.

Example:

> ls
Dockerfile
yumapro-sdk-eval-23.10-5.u2204.amd64.deb
# OR directory
yumapro-sdk-source-code
  1. Build the Docker image using the provided Dockerfile and specify YUMAPRO_SDK_SOURCE= path to the deb file or source code directory:

Example:

For building from the deb file:

sudo docker build -t yumapro-sdk-eval-docker . --no-cache --build-arg YUMAPRO_SDK_SOURCE=yumapro-sdk-eval-23.10-5.u2204.amd64.deb

For building from the source code:

sudo docker build -t yumapro-sdk-code-docker . --no-cache --build-arg YUMAPRO_SDK_SOURCE=yumapro-sdk-source-code

# Default arguments:
# LOG_DIR="docker-logs"
# SUDO_USER="user-1"
# SUDO_PASSWORD="password-1"
# YUMAPRO_SDK_DEST="/yumapro-sdk"
# YUMAPRO_SDK_SOURCE is a requirement.

Run Image

Once the image is built, you can run it with the following command:

sudo docker run -it yumapro-sdk-eval-docker

# Or if the image is built from the source code
sudo docker run -it yumapro-sdk-code-docker

Refer to the documentation YumaPro Docker User Guide for further instructions.