Setting up the AlmaLinux9 Container for Python and C/C++ Development using a Dockerfile¶
In this section, instead of simply pulling the AlmaLinux9 image, we will create a custom Dockerfile that:
- Installs essential development tools (e.g., GCC, Make, and CMake) for compiling C++ code.
- Installs Miniconda so you can easily manage Python packages.
- Sets up a working directory (e.g.,
/workspace
) and marks it as a volume. This enables you to mount a local folder to persist data even after the container is shut down.
Creating the Dockerfile¶
Create a file named Dockerfile.alma9
with the following content:
The RUN command updates the system and installs essential packages:
gcc
andgcc-c++
: Provide the compilers needed to build C++ code.make
andcmake
: Tools for automating builds.curl
: Needed to download the Miniconda installer.
Miniconda is installed using the ARM-specific installer script Miniconda3-latest-Linux-aarch64.sh. This provides a lightweight Python environment that you can be easily extended with additional Python packages.
Info
If you need a specific Python version or more libraries installed by default, add them to this Dockerfile or run them inside the container using conda install <package_name>
.
Note
The Dockerfile creates a /workspace
directory, sets it as the current working directory, and uses a VOLUME
instruction to indicate that this directory is intended for persistent storage. When you run the container, you can mount a local directory to /workspace
so that any data created or modified there is preserved even after the container stops.
Building and Running the Image¶
-
Build the Image
Open your Terminal and run:
This command builds the image and tags it as
alma9
.DO NOT forget the dot at the end of the command!
The single dot (.) at the end of the command sets the build context to the current directory. This means that the build expects to find the Dockerfile in the directory where the command is invoked. If the file is not there, the build fails.
-
Run the Container
Once the image is built, start a container interactively with:
This command creates a container (naming it
<process_name>
) from your custom image and mounts your host’s/path/to/local/workspace
to the container’s/workspace
volume. Any files you create or modify inside/workspace
will be stored on your host machine. It also works the other way around: any files in/path/to/local/workspace
will be accessible from inside the container.
Setting up the Miniconda Environment¶
Once inside the container, you can create and manage Python environments using Miniconda.
-
Create a New Conda Environment
Run the following command to create a new Conda environment named
python_env
:This creates a new environment with the latest versions of Python. It also installs the popular scientific computing libraries NumPy, Pandas, Matplotlib, and SciPy.
-
Activate the Conda Environment
Activate the environment with:
The prompt should change to show the active environment.