Search code examples
bashdockershelldocker-composeibm-mq

In docker, cannot execute script to manage ibm mq queues when lauching container


I have a dockerfile that is based on an IBM MQ homemade image (I don't have its sources but its a linux distro).

I want to run the image pass some scripts and keep it runing as daemon.

But each time I try to pass some commands for mq such as :

echo "DEFINE QLOCAL(TEST_01.TEST.SOMETHING.DEV)" | runmqsc TEST

nothing happen.

I have tried

RUN echo "DEFINE QLOCAL(TEST_01.TEST.SOMETHING.DEV)" | runmqsc TEST

then

ENTRYPOINT ["echo \"DEFINE QLOCAL(TEST_01.TEST.SOMETHING.DEV)\" | runmqsc TEST"]

or in my docker-compose file :

entrypoint: ["myscript.sh"] where myscript contain the previous bash script also tried creating a second container depending on my first one :

    mqsetup:
      image: myimage
      depends_on:
        - mq
      restart: "no"
      entrypoint: [ "bash", "-c", "sleep 10 && echo \"DEFINE QLOCAL(TEST_01.TEST.SOMETHING.DEV)\" | runmqsc TEST"]   

also tried to use the command method :

command:
  - myscript.sh

nothing works.

But if I exec into the container :

docker-compose exec mq /bin/bash

and then execute my script :

echo "DEFINE QLOCAL(TEST_01.TEST.SOMETHING.DEV)" | runmqsc TEST

my queue is created onto my queue manager TEST...

To be fairly honnest I am a bit lost, I know that my script is runned because I debuged it with some touch and echo to know if something happen...

At first I tought that it was too soon to paste the script but that's not it (tried to wait 5 minutes with sleep 5m before asking for launching the script but with no luck, and if I try to launch quicker than 5 min but by hand in exec mode, it works well...)


Solution

  • Without seeing the source of the image, I can only guess on what is occurring.

    The image by default will be starting up MQ, and your attempts at running runmqsc are interfering with that. You need to ensure that that script is allowed to run, and has had time to start up all its services, which will take longer than 2 seconds, before you execute your runmqsc command. After you execute your runmqsc you will need a no-op instruction that will keep the container running.

    If you were making use of icr.io/ibm-messaging/mq:latest then you could add .mqsc to /etc/mqm as suggested in the link provided by @David Maze

    What I think you are going have to do is add something like: (where runmqdevserver is the script that the current image runs.)

    entrypoint: ["/bin/bash", "-c"]
    command:
    - |
         runmqdevserver
         sleep 120  
         echo \"DEFINE QLOCAL(TEST_01.TEST.SOMETHING.DEV)\" | runmqsc TEST
         tail -f /dev/null
         
    

    to your DockerFile.

    By the way if runmqdevserver is what your image runs, then you could copy your mqsc script into /etc/mqm before running runmqdevserver as per the comment by David Maze.