This blog gives you an overview on how to run a MQ .NET Core Application on docker containers.

Create Project Folder:

  1. Create a new folder by name “SimplePut”.
  2. Copy SimplePut.cs and SimplePut.csproj files to the SimplePut folder created in Step 1 from the following location:
  3. Remove the following line from SimplePut.csproj file
  4. Copy amqmdnetstd.dll file to the SimplePut folder created in Step 1 from the following location:

Create a DockerFile for MQ .NET Core Application:

  1. Create a file by name “DockerFile” in SimplePut project folder which will be used as Dockerfile for sample application to build docker image.
  2. Add the below mentioned text to your DockerFile for either Windows Containers or Linux as follows:
    FROM microsoft/dotnet:latest
    WORKDIR /app
    #copy csproj and restore as distinct layers
    COPY *.csproj ./
    COPY *.dll ./
    RUN dotnet restore
    #copy and build everything else
    COPY . ./
    RUN dotnet publish -c Release -o out
    ENTRYPOINT ["dotnet", "out/SimplePut.dll"]

Build the Docker Image:

  1. Open command prompt to build the docker image.

  2. To verify whether docker is installed or not, issue the following command on command line as follows:
    docker -v
    Docker version 18.09.0, build 4d60db4
    If not, please install Docker for Linux/windows containers from Docker website.

  3. Navigate to your project folder and use the below command to build your Docker image.
    docker build -t simpleput .
    Note: Image_name should be lowercase alphabets.

  4. Docker image with simpleput will be successfully created. Output as follows:

    Sending build context to Docker daemon  2.381MB
    Step 1/8 : FROM microsoft/dotnet:latest
    ---> 81d80198a492
    Step 2/8 : WORKDIR /app
    ---> Using cache
    ---> 72afa181c56c
    Step 3/8 : COPY *.csproj ./
    ---> Using cache
    ---> 43bbfd1b9635
    Step 4/8 : COPY *.dll ./
    ---> Using cache
    ---> 4d81184ca6e3
    Step 5/8 : RUN dotnet restore
    ---> Using cache
    ---> f250db37f272
    Step 6/8 : COPY . ./
    ---> Using cache
    ---> 7bd622f5fead
    Step 7/8 : RUN dotnet publish -c Release -o out
    ---> Using cache
    ---> 2f8cb551ef9a
    Step 8/8 : ENTRYPOINT ["dotnet", "out/SimplePut.dll"]
    ---> Using cache
    ---> a9f01505ea8d
    Successfully built a9f01505ea8d
    Successfully tagged app:latest
  5. By issuing the following command, you can view the latest docker image created.

    docker images

  6. Output for the above command as follows:

    simpleput latest a9f01505ea8d 21 seconds ago 1.75 GB

Running the Docker Image:

  1. Run the docker image by passing arguments as follows:
    docker run simpleput -qm Test1 -q Q1 -h 9.yyy.zzz.ww -p 1423
  2. Program will be putting messages successfully onto the queue which is mentioned as arguments.
    Start of SimplePut Application
    MQ Parameters
    1) queueName = Q1
    2) keyRepository =
    3) cipherSpec =  
    4) host = 9.yyy.zzz.ww
    5) port = 1423
    6) channel = SYSTEM.DEF.SVRCONN
    7) numberOfMsgs = 1
    8) sslPeerName =
    9) keyResetCount = 0
    10) sslCertRevocationCheck = False
    Connecting to queue manager.. done 
    Accessing queue Q1.. done
    Message 1 <test message>.. put
    Closing queue.. done
    Disconnecting queue manager.. done
    End of SimplePut Application

Installing IBM MQ classes for .NET Standard

Join The Discussion

Your email address will not be published.