Hello World Example for Docker - UG1630

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

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

To create a Docker image, first create a makefile to compile hello.c:

CC      = gcc
CFLAGS  = -g
RM      = rm -f

default: all
all: hello
hello: hello.c
    $(CC) $(CFLAGS) -o hello hello.c
clean veryclean:
    $(RM) hello

To create a Dockerfile using the following. The intention is to print Hello World from hello.c when running the Docker image.

# 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 /workspace
COPY makefile hello.c ./
RUN make

# Choose the base parent image for deployment
FROM ubuntu:latest
WORKDIR /opt/xilinx/test
COPY --from=build /workspace/hello  ./
CMD ["/.hell"]

On the target, put the three (3) files in the same folder. In this example, the files are in amd_hello_kria/. Customize the example to a specific project: < vendorName_appName_targetName > and build and test on the target:

docker build -t amd_hello_kria .     # build the docker image 

docker run amd_hello_kria // test docker image

Now you can upload to your repository for testing. Create a user name on www.docker.com, remember your <username> and <password>. Then, upload the docker image into your private repository for staging:

sudo docker login --username <username> --password <your password> # login into dockerhub
docker build -t <username>/amd_hello_kria .                                                   # build for private repo
sudo docker push <username>/amd_hello_kria:latest                                    # push to private repo

Test using the following commands:

docker pull <username>/amd_hello_kria:latest                              # pull image
docker run <username>/amd_hello_kria:latest                              # run image