From 96972da09fe1f045a7cab50db1913f4543f0f3dc Mon Sep 17 00:00:00 2001
From: "Alex, Tony (PG/R - Comp Sci & Elec Eng)" <t.alex@surrey.ac.uk>
Date: Fri, 8 Nov 2024 03:44:45 +0000
Subject: [PATCH] Update container.def

---
 container.def | 66 ++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 47 insertions(+), 19 deletions(-)

diff --git a/container.def b/container.def
index 204172c..2ad4f84 100644
--- a/container.def
+++ b/container.def
@@ -1,25 +1,53 @@
-# Get the base image from nvidia/cuda Docker image.
-BootStrap: docker
-From: nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04 
+# Use NVIDIA CUDA 11.8 with cuDNN 8 for Ubuntu 22.04 as the base
+Bootstrap: docker
+From: nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
 
+### Recreating ubuntu22fairseq docker, with apptainer for testing
 %post
-    # Install special software or additions
-    apt-get update -y # Good practice, update the package database.
-    apt-get install -y      libopenblas-dev # Install the BLAS.
-    apt-get autoremove -y && apt-get autoclean -y # Good practice, to keep the Docker image as small as possible.
+    # Set the environment to noninteractive for apt installations
+    export DEBIAN_FRONTEND=noninteractive
 
-%environment
-    # Set some environment vars
-    export PATH=/opt/root/bin:$PATH
-    export LD_LIBRARY_PATH=/opt/root/lib:$LD_LIBRARY_PATH
-    export PYTHONPATH=/opt/root/lib
+    # Update the apt repository and install essential packages
+    apt-get update && \
+    apt-get install -y wget bzip2 && \
+    apt-get clean
 
+    # Download and install Anaconda
+    echo "Downloading and installing Anaconda..."
+    ANACONDA_INSTALLER="Anaconda3-2023.07-1-Linux-x86_64.sh"
+    wget https://repo.anaconda.com/archive/$ANACONDA_INSTALLER
+    bash $ANACONDA_INSTALLER -b -p /opt/conda
+    rm $ANACONDA_INSTALLER
+    echo "Anaconda installed."
 
-%runscript
-    # The command that will run when container is started via apptainer run command.
-    python /opt/root/tutorials/roofit/rf101_basics.py
+    # Set up conda path
+    echo "Setting up conda path..."
+    export PATH="/opt/conda/bin:$PATH"
+    
+    # Update conda and create a Python 3.9.13 environment as default
+    echo "Updating conda and configuring Python 3.9.13 environment..."
+    conda init bash
+    conda config --set always_yes yes --set changeps1 no
+    conda update -n base -c defaults conda
+    conda create -y -n py3913_env python=3.9.13  # Create a Python 3.9.13 environment
+    echo "Python 3.9.13 environment created."
+
+    # Clean up package cache to reduce image size
+    echo "Cleaning up package cache to reduce image size..."
+    rm -rf /var/lib/apt/lists/*
+    echo "Cleanup complete."
 
-%labels
-    # Add custom metadata to the container.
-    Author Me
-    Version v0.0.1
\ No newline at end of file
+%environment
+    # Set environment variables
+    export PATH="/opt/conda/envs/py3913_env/bin:/opt/conda/bin:$PATH"  # Ensure Python 3.9.13 from py3913_env is first in PATH
+    export LC_ALL=C.UTF-8
+    export LANG=C.UTF-8
+    export PYTHON="/opt/conda/envs/py3913_env/bin/python"  # Define PYTHON variable to point to Python 3.9.13 in py3913_env
+
+%runscript
+    # Default command when the container is run
+    echo "The container is equipped with Anaconda and all necessary dependencies."
+    echo "Activating the Python 3.9.13 conda environment (py3913_env) by default..."
+    source /opt/conda/etc/profile.d/conda.sh  # Source conda profile script
+    conda activate py3913_env  # Activate the Python 3.9.13 environment
+    exec bash  # Start a bash shell in the container for interactive use
\ No newline at end of file
-- 
GitLab