Customizing Python and SPSS deployment images in Watson Machine Learning
You can add customizations to your Python image by using Docker or Podman.
Adding customizations to Python image
Use the following sample Dockerfile to add customizations to your Python image.
Sample Dockerfile:
ARG base_image_tag
FROM ${base_image_tag}
# For installing system packages, use root:root
# e.g.
USER root:root
RUN microdnf install -y jq
# For installing to conda site-packages,
# use wsbuild:wsbuild
# e.g.
USER wsbuild:wsbuild
RUN source activate $WML_CONDA_ENV_NAME && \
pip install pendulum
USER wsuser:wscommon
You can run this Dockerfile by using the docker build
command, which returns the following output sample:
Sample code for Docker:
docker build -t test-custom-image:test-1 --build-arg base_image_tag=cp.stg.icr.io/cp/cpd/wml-dep-rt23-1-ms@sha256:5c7ba4fa9c1e6b9ab3bb3ce6285130216db80546ed02c63d1a2370e738a4e119 -f Dockerfile .
[+] Building 11.5s (7/7) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 362B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for cp.stg.icr.io/cp/cpd/wml-dep-rt23-1-ms@sha256:5c7ba4fa9c1e6b9ab3bb3ce6285130216db80546ed02c63d1a2370e738a4e119 0.0s
... snippet ...
=> => exporting layers 0.2s
=> => writing image sha256:9df9d2d3b16e63fc56b1a9003f237790a77c7f4ffb2f96df4fd0abffe1a6187d 0.0s
=> => naming to docker.io/library/test-custom-image:test-1
To use the sample code, you must update the following parameters:
- Set
user:group
parameter toroot:root
to install system packages. - After installing system packages, set
user:group
parameter towsbuild:wsbuild
to install python packages. - After installing Python packages, update
conda
environment name for$WML_CONDA_ENV_NAME
parameter. - After updating the
conda
environment, setuser:group
towsuser:wscommon
.
You can also run the Dockerfile in Podman by using the podman build
command, which returns the following output sample:
Sample code for Podman:
podman build -t test-custom-image:test-1 \
> --build-arg base_image_tag=cp.stg.icr.io/cp/cpd/wml-dep-rt23-1-ms@sha256:5c7ba4fa9c1e6b9ab3bb3ce6285130216db80546ed02c63d1a2370e738a4e119 -f Dockerfile .
STEP 1/6: FROM cp.stg.icr.io/cp/cpd/wml-dep-rt23-1-ms@sha256:5c7ba4fa9c1e6b9ab3bb3ce6285130216db80546ed02c63d1a2370e738a4e119
STEP 2/6: USER root:root
--> 1a710ccc1dae
... snippet...
--> f0ef896379fe
STEP 6/6: USER wsuser:wscommon
COMMIT test-custom-image:test-1
--> 1dc344ed12a0
Successfully tagged localhost/test-custom-image:test-1
1dc344ed12a0fb17e38b895db70e5cd5acc124bb4336f7388083ba0a4c83d637
As best practice, set the default USER
of the custom image to wsuser:wscommon
. The HOME
environment variable is set to /home/wsuser
in the deployment service.
Adding customizations to SPSS image
Use the following sample Dockerfile to add customizations to your SPSS image.
FROM <SPSS_RUNTIME_IMAGE> AS custom_image
# Install Exasol ODBC driver
RUN mkdir -p /opt/exasol
RUN wget -O /opt/exasol/EXASOL_ODBC.tar.gz \
https://www.exasol.com/support/secure/attachment/175398/EXASOL_ODBC-${EXASOL_ODBC_VERSION}.tar.gz
RUN ls -l /opt/exasol/EXASOL_ODBC.tar.gz
RUN cd /opt/exasol \
&& tar -xzf EXASOL_ODBC.tar.gz
RUN mv /opt/exasol/EXASolution_ODBC-${EXASOL_ODBC_VERSION}/* /opt/exasol
RUN rm -rf /opt/exasol/EXASolution_ODBC-${EXASOL_ODBC_VERSION} \
&& rm -rf /opt/exasol/EXASOL_ODBC.tar.gz
# enable Exasol ODBC Driver
RUN sed -i '2iExasol Client=Installed' ${SDAPDRIVER_HOME}/odbcinst.ini
USER ${BASE_USER_NAME}
Parent topic: Creating a custom image