Skip to content

Instantly share code, notes, and snippets.

@bretton
Last active October 10, 2024 16:18
Show Gist options
  • Save bretton/3eb1b2989d4150c4c63e62d10be5940b to your computer and use it in GitHub Desktop.
Save bretton/3eb1b2989d4150c4c63e62d10be5940b to your computer and use it in GitHub Desktop.
IBM-MQ with Podman, podman-compose and Ubuntu 24.04

IBM-MQ with Podman, podman-compose and Ubuntu 24.04

The following guide will help you get a containerised instance of IBM-MQ running on Ubuntu 24.04 with podman-compose and apparmour support.

Make sure you have the required software installed

sudo apt-get update
sudo apt-get -y install podman podman-compose podman-docker

Create a directory and change into it

mkdir -p ibm-mq && cd ibm-mq

Create the config and data directories and set permissions (needs attention)

mkdir -p config
mkdir -p qm1data
chmod 777 qm1data

Create the file config/20-config.mqsc which defines two queues

nano config/20-config.mqsc

* Define the DEV queue
DEFINE QLOCAL(DEV)

* Define the QM1 queue
DEFINE QLOCAL(QM1)

* Display the queues to verify creation
DISPLAY QLOCAL(DEV)
DISPLAY QLOCAL(QM1)

Add passwords to credentials files. Make sure to set your own passwords!

printf "YOUR-ADMIN-PASSW0RD" > config/mqAdminPassword.txt
printf "YOUR-APP-PASSWORD" > config/mqAppPassword.txt

Create the podman-compose.yml file as follows:

version: '3.8'

services:
  qm1:
    image: icr.io/ibm-messaging/mq:latest
    container_name: QM1
    secrets:
      - mqAdminPassword
      - mqAppPassword
    environment:
      - LICENSE=accept
      - MQ_QMGR_NAME=QM1
      - MQ_DEV=false
      - MQSC=/etc/mqm/20-config.mqsc
    ports:
      - "1414:1414"
      - "9443:9443"
    volumes:
      - ./qm1data:/mnt/mqm
      - ./config/20-config.mqsc:/etc/mqm/20-config.mqsc
    security_opt:
      - seccomp=unconfined
      - apparmor=podman
    restart: always
    command: ["--replace"]
    deploy:
      resources:
        limits:
          memory: 1g

volumes:
  qm1data:

secrets:
  mqAdminPassword:
    file: ./config/mqAdminPassword.txt
  mqAppPassword:
    file: ./config/mqAppPassword.txt

Start the container with

podman-compose -f ./podman-compose.yml up -d

Wait a minute and check the container logs with

podman logs QM1

You need to see the following to proceed:

The mqweb server is ready to run a smarter planet. The mqweb server started in 15.711 seconds.

Create a test.sh script as follows

#!/bin/bash

# Define MQ connection details
MQ_QUEUE_MANAGER="QM1"
MQ_QUEUE="DEV"
MQ_USER="app"
MQ_PASSWORD="YOUR-APP-PASSWORD"

# Write a message to the DEV queue
echo "Testing writing data to the DEV queue in MQ..."
MESSAGE="Hello from test script"

# Use MQSC to put the message inside the container
podman exec QM1 /opt/mqm/bin/runmqsc $MQ_QUEUE_MANAGER << EOF
DEFINE QREMOTE('$MQ_QUEUE') RQMNAME('$MQ_QUEUE_MANAGER') RNAME('$MQ_QUEUE') RQMNAME('$MQ_QUEUE_MANAGER')
EOF

echo "$MESSAGE" | podman exec -i QM1 /opt/mqm/samp/bin/amqsput $MQ_QUEUE $MQ_QUEUE_MANAGER

if [ $? -eq 0 ]; then
  echo "Message successfully written to the DEV queue."
else
  echo "Failed to write message to the DEV queue."
  exit 1
fi

Make it executable

chmod +x test.sh

Check the container is functioning correctly by running test.sh. The output should be something like:

./test.sh 
Testing writing data to the DEV queue in MQ...
5724-H72 (C) Copyright IBM Corp. 1994, 2024.
Starting MQSC for queue manager QM1.


No MQSC commands read.
Sample AMQSPUT0 start
target queue is DEV
Sample AMQSPUT0 end
Message successfully written to the DEV queue.

You can stop the container with the following command

podman-compose down --timeout 30

And if you ever get a container stuck in STOPPING and podman-compose cannot clear it, try

kill -9 $(podman container inspect QM1  -f '{{.State.Pid}}')

If you wish to send data to the MQ system, get remote clients to access the host on port 1414 with appropriate Websphere MQ client software.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment