Dockerfile - UG1630

Kria SOM App Store Applications Developer Deployment Guide for Ubuntu (UG1630)

Document ID
UG1630
Release Date
2023-08-11
Revision
1.0 English

In addition to the application source code, a dockerfile is needed to describe the containerization of the application. Generally, the dockerfile is place in the top-level directory of the source code. This file contains list of instructions. The first must be the FROM <ImageName> instructions, that specify the parent image (base image) to be used for this image. A detailed dockerfile format is documented in Dockerfile Reference. A normal docker file could contain instructions to:

  • Use the FROM reference to the base/parent image using FROM ImageName.
  • Set the working directory in the rootfs using the WORKDIR for any RUN, CMD, ENTRYPOINT, COPY and ADD using the WORKDIR /path/to/workdir.
  • Install the required dependencies using RUN to run regular commands in the base image (for example: cd, apt install, etc.) using the RUN <command>.
  • Setup environment variables using ENV with the ENV <key>=<value> ....
  • Copy the required files to the rootfs from local or another image using COPY or ADD COPY
    [--chown=<user>:<group>] <src>... <dest>
    ADD [--chown=<user>:<group>] [--checksum=<checksum>] <src>... <dest>
  • Expose the network ports (docker network) using:
    EXPOSE <port> [<port>/<protocol>...]
  • Run the actual application using CMD. Each image should only have one CMD: CMD ["executable","param1","param2"].

The following is an example dockerfile:

# Choose the base parent image for build
FROM ubuntu:latest as build 

RUN apt-get update && \
apt-get install -y build-essential git cmake autoconf libtool pkg-config

WORKDIR /src

COPY CMakeLists.txt main.cpp ./

RUN mkdir build && cd build

RUN cmake .. && make





# Choose the base parent image for deployment
FROM ubuntu:latest

WORKDIR /opt/xilinx/test

COPU –from=build /src/build/test-app ./

CMD [“/.test-app”]

Other example docker files for the Kria SOM project are available in GitHub (https://github.com/Xilinx/kria-docker). If using a similar build environment for multiple applications development, it might make sense to create a build-image docker image, with all the tools installed, and use that docker image to build the application image. An example is the kria-developer docker image in the AMD docker hub. The base developer and application runtime docker images are available there. Optionally they can be leveraged by an app developer as a basis for a docker-based application image. See the docker documentation for information on multi-stage builds.