Dockerfile For Esmini: Setup & Run Guide

Alex Johnson
-
Dockerfile For Esmini: Setup & Run Guide

Hey guys! This article is all about setting up and running esmini using Docker and Podman. I've got a Dockerfile that streamlines the process, making it easier to get esmini up and running, and I'll walk you through everything. Whether you're a Docker newbie or a seasoned pro, this guide will provide you with the necessary steps and commands to make it work. We will be covering the interactive and non-interactive methods, and also how to use Podman with SELinux. Ready to dive in?

Setting Up Your Environment with the Dockerfile

Let's start by breaking down the Dockerfile provided. This file is essentially a set of instructions for building a Docker image. The image will include all the necessary dependencies to run esmini. The Dockerfile is written to work with Ubuntu 22.04, providing a reliable and consistent environment.

Here's the breakdown of the Dockerfile:

FROM ubuntu:22.04

RUN apt update
RUN apt install --assume-yes build-essential gdb ninja-build git pkg-config libgl1-mesa-dev libpthread-stubs0-dev libjpeg-dev libxml2-dev libpng-dev libtiff5-dev libgdal-dev libpoppler-dev libdcmtk-dev libgstreamer1.0-dev libgtk2.0-dev libcairo2-dev libpoppler-glib-dev libxrandr-dev libxinerama-dev curl cmake black

WORKDIR /mnt/esminiMainFolder

RUN mkdir -p build && cd build && rm -rf *
WORKDIR /mnt/esminiMainFolder/build
RUN cmake ..
RUN cmake --build . --config Release --target install

WORKDIR /mnt/esminiMainFolder
CMD ["/bin/bash"]
  • FROM ubuntu:22.04: This line specifies the base image for our Docker image. We're using Ubuntu 22.04 as the foundation.
  • RUN apt update and RUN apt install: These commands update the package lists and install the required dependencies, like build-essential, cmake, and other libraries needed to build and run esmini.
  • WORKDIR /mnt/esminiMainFolder: This sets the working directory inside the container.
  • The subsequent RUN commands create a build directory, navigate into it, and use cmake to configure and build esmini. The --config Release flag ensures that we build in release mode, and --target install installs the built binaries.
  • CMD ["/bin/bash"]: This specifies the command that runs when the container starts, opening a bash shell. You'll land right in the working directory, ready to explore or run esmini.

Interactive vs. Non-Interactive Modes

Interactive Mode: In interactive mode, you launch a container and interact with it directly. This is great for testing and experimenting. You'll use commands like docker run -it or podman run -it. The -it flags allocate a pseudo-TTY and keep STDIN open even if not attached. You can input commands and see the output in real-time.

Non-Interactive Mode: In non-interactive mode, you build an image and then run it. This is often used for automating tasks or when you don't need to directly interact with the container. You build the image using docker build or podman build, and then you run the container.

Running the Dockerfile: Interactive Method

Let's get our hands dirty with interactive mode. This is a fantastic way to test things out. We'll use the command provided to run our image interactively, giving us direct access to the container's shell.

Docker Interactive Run Command: docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:rw --rm -v .:/mnt/esminiMainFolder:z --shm-size=2g ubuntu:22.04 /bin/bash

Here's what each part does:

  • -it: Runs the container in interactive mode, allocating a pseudo-TTY and keeping STDIN open.
  • -e DISPLAY=$DISPLAY: Sets the DISPLAY environment variable, allowing graphical applications (like esmini) to display on your host machine.
  • -v /tmp/.X11-unix:/tmp/.X11-unix:rw: Mounts the X11 socket, allowing the container to access your host's display.
  • --rm: Automatically removes the container when it exits.
  • -v .:/mnt/esminiMainFolder:z: Mounts the current directory (where the Dockerfile is located) into the container's /mnt/esminiMainFolder directory, making your project files accessible inside the container. The z option handles SELinux context.
  • --shm-size=2g: Sets the shared memory size to 2GB, which can improve performance.
  • ubuntu:22.04: Specifies the base image to use for the container.
  • /bin/bash: Runs bash when the container starts.

Just paste the above line into your terminal, and boom! You're inside the container. You can then navigate to /mnt/esminiMainFolder/build to access the compiled esmini.

Running the Dockerfile: Podman and SELinux

Podman and SELinux: For those of you using Podman, especially on systems with SELinux, you need to make a slight adjustment to your run command. SELinux is a security feature that restricts the access of processes. We use --security-opt label=type:container_runtime_t to tell Podman to correctly label the container's processes, ensuring that it can access the host's resources.

Podman Interactive Run Command: podman run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:rw --security-opt label=type:container_runtime_t --rm -v .:/mnt/esminiMainFolder:z --shm-size=2g ubuntu:22.04 /bin/bash

Non-Interactive Method

Non-interactive mode lets you build the image and then run it later. This is helpful for CI/CD pipelines or when you want to easily reproduce the environment.

Docker Non-Interactive Run Command: docker build -t esmini_ubuntu:22.04 .; docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:rw --rm -v .:/mnt/esminiMainFolder:z --shm-size=2g esmini_ubuntu:22.04

Here's what is happening:

  1. docker build -t esmini_ubuntu:22.04 .: Builds the Docker image. The -t flag tags the image with the name esmini_ubuntu:22.04 so you can refer to it later, and the . specifies the build context (the current directory).
  2. docker run ...: Runs the container, the same as the interactive method but using the tagged image name.

Podman Non-Interactive Run Command: podman build -t esmini_ubuntu:22.04 .; podman run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:rw --security-opt label=type:container_runtime_t --rm -v .:/mnt/esminiMainFolder:z --shm-size=2g esmini_ubuntu:22.04

The Podman non-interactive command is nearly identical to the Docker version, except that it uses podman build and adds the SELinux option during the podman run command.

Running Your Esmini Application

Once you're inside the container, navigate to the build directory, and you should find the compiled esmini executable. You can run the application and start interacting with esmini.

Troubleshooting Tips

  1. Display Issues: Make sure your X11 forwarding is set up correctly. Ensure you have the xhost +local:root command executed on your host machine before running the container. This command allows the container to connect to your X server.
  2. Permissions: If you encounter permission problems, ensure that the user inside the container has the necessary permissions to access the files. The -v .:/mnt/esminiMainFolder:z option should handle SELinux context correctly.
  3. Dependencies: If you are still running into issues, double-check that all dependencies were installed successfully by inspecting the output of the build and run commands.

Conclusion

There you have it, guys! You've successfully created a Dockerfile, built a Docker image, and run esmini in a container. Docker and Podman are awesome tools that make it easier to manage dependencies and create reproducible environments. This makes it a snap to set up and get started. Happy containerizing!

For more information on containerization and best practices, I recommend checking out the Docker documentation at https://docs.docker.com/. You can also check the Podman documentation at https://podman.io/.

You may also like