Docker container taking too long to run application

Hi,
I am working on a Yocto build for tdx-reference-multimedia-qt6-image and have containerized a Qt application for the Apalis iMX8 module. I successfully built the Docker image and pulled it onto my Toradex board. When I run the container, the application executes, but it takes almost 3 minutes for the Qt application to display. The Docker image size is 456MB, and I need to reduce both the image size and the execution time to seconds.

I am also attaching dockerfile below


`# Stage 1: Build Stage
FROM torizon/qt6-wayland:next AS build

Set environment variables

ENV DEBIAN_FRONTEND=noninteractive

Install build dependencies

RUN apt-get update && apt-get install -y
build-essential
cmake
qt6-base-dev
qt6-declarative-dev
libqt6quick6
libqt6qml6
qml6-module-qtquick
qml6-module-qtqml
qt6-wayland
qt6-tools-dev-tools
&& rm -rf /var/lib/apt/lists/*

Set the working directory

WORKDIR /app

Copy the project files

COPY . .

Configure the build with CMake

RUN cmake -S . -B build -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/cmake/Qt6

Build the application

RUN cmake --build build – -j$(nproc)

Stage 2: Runtime Stage

FROM torizon/qt6-wayland:next

Install only the necessary runtime dependencies

RUN apt-get update && apt-get install -y
libqt6quick6
libqt6qml6
qml6-module-qtquick
qml6-module-qtqml
qml6-module-qtquick-window
qml6-module-qtqml-workerscript
&& rm -rf /var/lib/apt/lists/*

Copy the built application from the build stage

COPY --from=build /app/build/infotainment /usr/local/bin/infotainment

Make the binary executable

RUN chmod +x /usr/local/bin/infotainment

Set the entry point

CMD [“/usr/local/bin/infotainment”]
`


Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


To address the issue of your Docker container taking too long to run the Qt application on the Apalis iMX8 module, you can consider the following optimizations:

1. Reduce Docker Image Size

Reducing the Docker image size can help in faster loading and execution. Here are some tips:

  • Minimize the number of layers: Combine multiple RUN commands into a single one.
  • Use a smaller base image: If possible, use a smaller base image that still meets your requirements.
  • Remove unnecessary files: Clean up any temporary files or caches created during the build process.

2. Optimize Dockerfile

Here is an optimized version of your Dockerfile:

# Stage 1: Build Stage
FROM torizon/qt6-wayland:next AS build

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive

# Install build dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    cmake \
    qt6-base-dev \
    qt6-declarative-dev \
    libqt6quick6 \
    libqt6qml6 \
    qml6-module-qtquick \
    qml6-module-qtqml \
    qt6-wayland \
    qt6-tools-dev-tools \
    && rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /app

# Copy the project files
COPY . .

# Configure the build with CMake
RUN cmake -S . -B build -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/cmake/Qt6

# Build the application
RUN cmake --build build -- -j$(nproc)

# Stage 2: Runtime Stage
FROM torizon/qt6-wayland:next

# Install only the necessary runtime dependencies
RUN apt-get update && apt-get install -y \
    libqt6quick6 \
    libqt6qml6 \
    qml6-module-qtquick \
    qml6-module-qtqml \
    qml6-module-qtquick-window \
    qml6-module-qtqml-workerscript \
    && rm -rf /var/lib/apt/lists/*

# Copy the built application from the build stage
COPY --from=build /app/build/infotainment /usr/local/bin/infotainment

# Make the binary executable
RUN chmod +x /usr/local/bin/infotainment

# Set the entry point
CMD ["/usr/local/bin/infotainment"]

3. Use a Local Proxy for Package Downloads

As mentioned in the context, you can set up a local proxy to cache package downloads, which can speed up the build process. This is particularly useful if you frequently rebuild your Docker images.

4. Optimize Container Startup Time

To reduce the time it takes for the container to start and the application to display, consider the following:

  • Preload necessary libraries: Ensure that all required libraries are preloaded to avoid delays during runtime.
  • Optimize systemd services: If your application does not depend on certain services (e.g., network), you can disable them to speed up the boot process. Refer to the context on how to edit systemd services to make the boot faster.

5. Measure and Analyze Boot Time

Use systemd-analyze to measure and analyze the boot time. This can help you identify any bottlenecks in the boot process and optimize accordingly.

6. Blacklist Unnecessary Drivers

If there are any unnecessary drivers being loaded during boot, you can blacklist them to reduce boot time. Refer to the context on how to blacklist WiFi drivers to optimize boot time.

7. Use TorizonCore Builder Tool

Use the TorizonCore Builder Tool to further optimize the system for your specific needs. This tool allows you to customize and optimize TorizonCore for your application.

By applying these optimizations, you should be able to reduce both the Docker image size and the execution time of your Qt application.

Please, also check if these links can help you solve your problem:

Boot time for a typical QT application on IMX7 modules.

I need to optimize the container startup time. Currently, it takes 3 minutes between entering the command to start Docker and the display of the Qt application in the container. I need to reduce this time to a few seconds.

root@apalis-imx8-07239822:~# time docker run --rm -it -e XDG_RUNTIME_DIR=/run -e WAYLAND_DISPLAY=wayland-0 -v /run:/run srejivesree/automotive:automotive
QStandardPaths: wrong permissions on runtime directory /run, 0755 instead of 0700
libEGL warning: wayland-egl: could not open /dev/dri/card0 (No such file or directory)
CSV file path: “:/csv/radio.csv”

Hi @SruthiSathyan ,
Unfortunately, we have not tested container on reference-multimedia-images, If you want to use conatiner you can directly use our Torizon OS.