BLOGS & ARTICLES

Containerizing GAMS with Standard Python Libraries using Docker

This article discusses a complex task of containerizing GAMS (General Algebraic Modeling System) along with standard Python libraries in a single Docker container, due to the absence of readily available online resources and GAMS's own limited Docker documentation.

Here are the key steps we undertook to resolve the issue:

1.Preparation of Docker Base Image: We started with a base image of Ubuntu in Docker. Then, we installed necessary dependencies and Python libraries that our application required, like GCC, Git, Ninja-build, libglib2.0-0, etc.

2.Installation of Anaconda: We installed the Miniconda distribution to help manage our Python environment.

3.Installation of GAMS: Downloaded GAMS installer and ran it. Included GAMS in our environment path to ensure it was accessible for execution.

4.Integration of Application Code: Copied our application code files, including Python scripts and supporting modules, into the Docker container's workspace.

5.Provision of GAMS license: Added the GAMS license file into the appropriate directory within the Docker container.

img

6.Creation of Entrypoint Scripts: Developed shell scripts (setup_conda.sh and docker_entrypoint.sh) to set up the conda environment, install Python packages, and initiate our Python applications respectively. Ensured that these scripts were executable.

7.Entrypoint Configuration: Configured Docker to run our setup_conda.sh script upon launching a container, which in turn would initiate our docker_entrypoint.sh script.

img

This process enabled us to create a Docker image that could run GAMS and standard Python libraries in harmony. This image could be deployed seamlessly in various environments without worrying about dependencies, offering the benefits of containerization for our GAMS application.

Preparation of Entrypoint Scripts: As our application relies on several Python libraries and a specific Python environment managed by conda, we developed a shell script (setup_conda.sh) to set up this environment within the Docker container. This script activates the 'gams' conda environment, installs GAMS Python bindings, and other required Python packages. We also created another shell script (docker_entrypoint.sh) that is responsible for initiating our Python applications.

A key reason we required setup_conda.sh was because, while building the Docker image, we weren't within the context of a shell session, and thus couldn't directly activate a conda environment. This issue could potentially cause failures when trying to install Python packages or run Python scripts that rely on the specific Python environment. By creating a separate script to manage conda setup, we were able to establish the necessary environment during runtime instead of build-time, ensuring the required Python packages and configurations were correctly set up.

Entrypoint Configuration: We configured Docker to run our setup_conda.sh script upon launching a container. This script ensures the necessary conda environment and Python packages are set up and then triggers docker_entrypoint.sh to run our Python applications.

Next Article
Related Blogs & Articles
Backing Up & Restoring Odoo with Docker: A Comprehensive Guide

In the ever-evolving world of software, the importance of backup and restoration can never be overstated. While working with...

IdeatoLife Enhances Image Analysis With Thya Technology

Introducing Thya Technology, an exciting spin-off emerging from the renowned (IVUL) at KAUST

The Power Of Explainable AI: Bringing Transparency And Trust To Artificial Intelligence

Artificial Intelligence (AI) has made remarkable strides in recent years, permeating various aspects of our lives...

IdeatoLife Unveils Onex Studio: A Revolutionary Software Development Platform To Boost Innovation

Artificial Intelligence (AI) has made remarkable strides in recent years, permeating various aspects of our lives...

Sign Up For Exclusive Access
And Updates From Ideatolife.