use docker-compose to generate an image –only–

I am using a Jenkins Pipeline to create a Docker Image and store it on a Docker Hub. The sequence of events are as follows:

  1. Pull down the code from Gitlab
  2. use “docker-compose” to build the Image file on the “slave” machine
  3. copy the Image file to the Docker Registry
  4. Erase the Image file.

To do this, I am using the code below:

pipeline {
  environment {
    registry = "<user_name>/object"
    registryCredential = 'dockerhub'
  }
  agent { label 'ubuntu16.04-slave-two' }
  stages {
    stage('Cloning Git') {
        steps {
                ....
            }
    }
    stage('Building image') {
      steps{
        sh '/usr/local/bin/docker-compose up --build '
      }
    }
    stage('Deploy Image') {
      steps{
        script {
          docker.withRegistry( '', registryCredential ) {
            dockerImage.push()
          }
        }
      }
    }
    stage('Remove Unused docker image') {
      steps{
        sh "docker rmi $registry:$BUILD_NUMBER"
      }
    }
  }
}

Everything seems to be working except this command:

 sh '/usr/local/bin/docker-compose up --build '

This does work – but – because I am using docker up, it starts the server (after Jenkins has created the image).

What I need is a way to generate (and name) the image so that it can be copied to Docker Hub using the docker-compose command.

Is this possible – or – can only the docker command itself be used to create a Docker Image.

Here is a reduce version of the docker-compose.yml file (the actual one has more services):

version: '3'

services:
  authorize-service:
    build: ./authorizations
    container_name: authorize-service
    environment:
      - DB_IP=XX.XX.XX.XX
      - DB_PORT=1521
      - DB_SID=TEST
      - DB_USER=<id>
      - DB_PASS=<password>
    ports:
      - 2700:5000
    networks:
      - tempnetwork

  website:
    build: ./website
    container_name: authorize-website
    links:
      - authorize-service
    volumes:
      - ./website:/var/www/html
    ports:
      - 5000:80
    networks:
      - tempnetwork
    depends_on:
      - authorize-service

networks:
  tempnetwork:
    driver: bridge

Any help, hints or advice would be greatly appreciated.

TIA

Source: StackOverflow