0

I would like to use docker-compose to start an IBM MQ server and a Python "pymqi" client connecting on server.

To achieve this, I wrote three Docker containers: cpython, pymqi and application.
application is based on pymqi itself based on cpython (to separate concerns).

I keep getting pymqi.MQMIError: MQI Error. Comp: 2, Reason 2195: FAILED: MQRC_UNEXPECTED_ERROR.

I've investigated in /var/mqm/qmgrs/QM1/errors/ and in /var/mqm/errors/ (as suggested by T.Rob) I think something is wrong in pymqi container but can't find what. The most frustrating part is that Docker client example works like a charm !

Source codes used below (sandbox available on my repo)

cpython Dockerfile

###
### Compiled home made CPython 3 docker image upon Ubuntu.
###

FROM ubuntu:18.04

RUN apt-get update -y

RUN apt-get install -y --no-install-recommends \
    bash \
    bc \
    ca-certificates \
    coreutils \
    debianutils \
    build-essential \
    file \
    findutils \
    gawk \
    grep \
    libc-bin \
    lsb-release \
    mount \
    passwd \
    procps \
    sed \
    tar \
    vim \
    wget

RUN apt-get install -y --no-install-recommends \
    zlib1g-dev \
    libncurses5-dev \
    libgdbm-dev \
    libnss3-dev \
    libssl-dev \
    libreadline-dev \
    libffi-dev

ARG PYTHON_MAJOR=3
ARG PYTHON_MINOR=8
ARG PYTHON_MICRO=2
ENV PYTHON_VERSION=${PYTHON_MAJOR}.${PYTHON_MINOR}.${PYTHON_MICRO}

RUN echo "Building CPython ${PYTHON_VERSION}"

ENV PYTHON_BINARY=python${PYTHON_MAJOR}.${PYTHON_MINOR}
ENV PYTHON_ARCHIVE_DIRECTORY=Python-${PYTHON_VERSION}
ENV PYTHON_ARCHIVE_FILENAME=${PYTHON_ARCHIVE_DIRECTORY}.tgz
ENV PYTHON_ARCHIVE_URL=https://www.python.org/ftp/python/${PYTHON_VERSION}/${PYTHON_ARCHIVE_FILENAME}
ENV ROOT_DIRECTORY=/tmp
ENV ARCHIVES_DIRECTORY=${ROOT_DIRECTORY}/PythonArchives
ENV EXTRACT_DIRECTORY=${ARCHIVES_DIRECTORY}/${PYTHON_ARCHIVE_DIRECTORY}

# Download archive
RUN mkdir --parents ${ARCHIVES_DIRECTORY}
RUN wget --quiet ${PYTHON_ARCHIVE_URL} --directory ${ARCHIVES_DIRECTORY}

# Extract archive
RUN tar --extract --file ${ARCHIVES_DIRECTORY}/${PYTHON_ARCHIVE_FILENAME} --directory ${ARCHIVES_DIRECTORY}

# Start compiling CPython
RUN cd ${EXTRACT_DIRECTORY} && ./configure --enable-optimizations
RUN cd ${EXTRACT_DIRECTORY} && make --jobs 8
RUN cd ${EXTRACT_DIRECTORY} && make altinstall

# Reset default python3 symbolic link
RUN unlink /usr/bin/python3
RUN ln -sv /usr/local/bin/${PYTHON_BINARY} /usr/bin/python3

# Remove shebang from /usr/bin/lsb_release to unblock pip (c.f. https://stackoverflow.com/q/44967202/5037799)
RUN sed -i 1d /usr/bin/lsb_release

# Update Python 3 essential modules
RUN python3 -m pip install -U pip setuptools


pymqi Dockerfile

###
### Reworked docker image from https://developer.ibm.com/answers/questions/488740/running-mqclient-pymqi-in-docker/
###

FROM richarddally/cpython:3.8.2_18.04

# Download and extract the MQ installation files
ARG DIR_EXTRACT=/tmp/mq

ENV ARCHIVE_FILENAME=mqadv_dev914_ubuntu_x86-64.tar.gz

# The URL to download the MQ installer from in tar.gz format
ARG MQ_URL=https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqadv/${ARCHIVE_FILENAME}

RUN echo $MQ_URL
RUN mkdir -p $DIR_EXTRACT && cd $DIR_EXTRACT

RUN wget --quiet $MQ_URL
RUN tar --ungzip --extract --file mqadv_dev914_ubuntu_x86-64.tar.gz --directory $DIR_EXTRACT
RUN rm ${ARCHIVE_FILENAME}

# Recommended: Remove packages only needed by this script
RUN apt-get purge -y ca-certificates curl

# Recommended: Remove any orphaned packages
RUN apt-get autoremove -y --purge

# Recommended: Create the mqm user ID with a fixed UID and group, so that the file permissions work between different images
RUN groupadd --system --gid 999 mqm
RUN useradd --system --uid 999 --gid mqm mqm
RUN usermod -G mqm root

# The MQ packages to install
ARG MQ_PACKAGES="ibmmq-client ibmmq-sdk ibmmq-runtime"

# Find directory containing .deb files
ARG DIR_DEB=${DIR_EXTRACT}/MQServer

# Find location of mqlicense.sh
ARG MQLICENSE=${DIR_EXTRACT}/MQServer/mqlicense.sh

# Accept the MQ license
RUN ${MQLICENSE} -text_only -accept

RUN echo "deb [trusted=yes] file:${DIR_DEB} ./" > /etc/apt/sources.list.d/IBM_MQ.list

# Install MQ using the DEB packages
RUN apt-get update
RUN apt-get install -y $MQ_PACKAGES

# Remove 32-bit libraries from 64-bit container
RUN find /opt/mqm /var/mqm -type f -exec file {} \; | awk -F: '/ELF 32-bit/{print $1}' | xargs --no-run-if-empty rm -f

# Remove tar.gz files unpacked by RPM postinst scripts
RUN find /opt/mqm -name '*.tar.gz' -delete

# Recommended: Set the default MQ installation (makes the MQ commands available on the PATH)
RUN /opt/mqm/bin/setmqinst -p /opt/mqm -i

# Clean up all the downloaded files
RUN rm -f /etc/apt/sources.list.d/IBM_MQ.list

RUN rm -rf ${DIR_EXTRACT}

# Apply any bug fixes not included in base Ubuntu or MQ image.

# Don't upgrade everything based on Docker best practices https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#run
RUN apt-get upgrade -y sensible-utils

# End of bug fixes
RUN rm -rf /var/lib/apt/lists/*

# Optional: Update the command prompt with the MQ version
RUN echo "mq:$(dspmqver -b -f 2)" > /etc/debian_chroot && rm -rf /var/mqm

ENV LANG=en_US.UTF-8

RUN export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/mqm/lib64/

# Support the latest functional cmdlevel by default
ENV MQ_QMGR_CMDLEVEL=802

# Always put the MQ data directory in a Docker volume
VOLUME /var/mqm
RUN chmod +x /var/mqm


application Dockerfile (filename: dockerfile.ibm_mq_client)

FROM richarddally/pymqi

RUN mkdir -p /app

WORKDIR /app

# Install requirements
ADD requirements.txt /app
RUN python3 -m pip install -r requirements.txt

ADD mqclient.py /app

ENTRYPOINT ["python3", "/app/mqclient.py"]


mqclient.py code

import pymqi

queue_manager = 'QM1'
qmgr = pymqi.connect(queue_manager)

qmgr.disconnect()


docker-compose.yml configuration file

version: '3'
services:
  client:
    build:
      context: .
      dockerfile: dockerfile.ibm_mq_client
    network_mode: host
    depends_on:
      - server
  server:
    image: "ibmcom/mq"
    environment:
      - LICENSE=accept
      - MQ_QMGR_NAME=QM1
    ports:
      - "1414:1414" # Queue manager
      - "9443:9443" # Web console
Richard Dally
  • 1,432
  • 2
  • 21
  • 38
  • Hi Richard, please run and provide output from the following in the container where the client code executes. `echo $HOME; ls -ld $HOME`. – JoshMc Jun 13 '20 at 14:59
  • Hello @JoshMc, `$HOME` is pointing on `/root`. Do you think it's related to running as root instead of another user (e.g. `mqm`) – Richard Dally Jun 13 '20 at 15:27
  • What does `ls` show? – JoshMc Jun 13 '20 at 15:32
  • `rwx------ 1 root root 4096 Apr 24 12:21 /root` – Richard Dally Jun 13 '20 at 15:33
  • Is that writable by the application? If not set `$HOME` to a location that is writable. MQ needs to create a `$HOME/.mqm` directory. I'll write an answer later. Let me know if it works. – JoshMc Jun 13 '20 at 15:57
  • Note you can even override `$HOME` directly in your python code as long as it is before you connect to the queue manager. – JoshMc Jun 13 '20 at 16:18
  • I tried `ENV HOME=/app` in Dockerfile, when I `docker run -it --entrypoint /bin/bash 67089895ad13 -s`, I'm as `root` in `/app`, I can touch/mkdir in `/app`. I still get `2195` on `docker-compose up`. – Richard Dally Jun 13 '20 at 17:29
  • Did you confirm `echo $HOME; ls -ld $HOME` shows `/app`? Anything created under `$HOME/IBM/MQ/data/errors` ? – JoshMc Jun 13 '20 at 18:04
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/215910/discussion-between-richard-dally-and-joshmc). – Richard Dally Jun 13 '20 at 21:18
  • @RichardDally, Could you please share your working solution? I'm also getting the same error and unable to make progress. Appreciate your help. Thanks in advance! – testbg testbg May 20 '21 at 20:18

0 Answers0