Python

Python

Python

 View Only

Creating your first Python Container Image

By Steven Pitman posted Fri November 15, 2024 08:19 AM

  

The IBM Open Enterprise SDK for Python 3.13 is now available as a container image for z/OS Container Platform. With this, you can now run your Python workloads in a container. This blog will teach you how to run a sample Python script within a container. 

Prerequisites

  • z/OS System with z/OS Container Platform installed 
  • An SMP/E license for the Open Enterprise SDK for Python and z/OSCP that come with their respective entitlement keys 
  • Entitlement keys should be found in the attached entitlement memos 

  

Obtaining the Python Container images 

To obtain the Python images, you can run the following commands: 

 

podman pull icr.io/zoscp/python:latest --creds iamapikey:<python image entitlement key> 

  

Creating a Python Container image 

To start, you will need a script that you want to run with Python. You will need to copy all dependencies into the container. For this example, we’re going to be copying one script named run_in_container.py, and having that script get run when the container is run. This all goes inside a file named Containerfile, and must be tagged as ISO8859-1 using chtag -tc ISO8859-1 Containerfile.  

 

FROM python:3.13.0 

# Create a location to store the Python script 
RUN mkdir /tmp/python 

# Copy our script to this new location 
COPY "run_in_container.py" /tmp/python 

# Set the current directory to our script location 
WORKDIR "/tmp/python" 

# Run IBM Open Enterprise SDK for Python 
CMD python3 run_in_container.py 

To then build the container image, you can run the following: 

 

podman build -t container_test:latest . 

  

container_test is the name of the container, and can be changed to anything. 

latest is the tag of the container that we will be making.  

 

With the Python container image built, you can confirm this by running: 

podman images 

 

And should see the container that you created above.

  

Running the Python Container image 

To run the newly created container image, you can use the following command: 

podman run --rm container_test 

The –rm flag specifies that when the container has been stopped, it will be deleted. With this having ran, you've now created and ran your first Python container workload.

  

 

 

0 comments
29 views

Permalink