简体   繁体   中英

Error when transferring Docker Image to Docker Hub using Jenkins Pipeline

Below is a portion of a Jenkins Pipeline Script that I am using to build a Docker Image and Deploy it to the Docker Hub. The problem that I am having is that after executing the Pipeline, the Docker Image is not transferred to Docker Hub ~and~ the local Docker Image (created during the process) is not erased.

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

Even though I get a SUCCESS message when building the image :

   Successfully built fe86784636c2
   Successfully tagged <docker_hub_id>object44_website:latest

The image is not transferred over to the Docker Hub.

Below is the log I got when running the Pipeline code:

Started by user Jenkins Admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on ubuntu16.04-slave-two in /var/jenkins/workspace/oracle-client-with-flask
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Cloning Git)

[... snip ...']

Building authorize-service
Step 1/11 : FROM oraclelinux:7
 ---> a803b2474b20

[... snip ...]

Step 3/4 : COPY . /var/www/html/
 ---> Using cache
 ---> e0b4cd5713c0
Step 4/4 : EXPOSE 80
 ---> Using cache
 ---> fe86784636c2
Successfully built fe86784636c2
Successfully tagged <docker_hub_id>object44_website:latest
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy Image)
[Pipeline] sh
+ docker push <docker_hub_id>/object:44
The push refers to a repository [docker.io/<docker_hub_id>/object]
An image does not exist locally with the tag: <docker_hub_id>/object
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Remove Unused docker image)
Stage "Remove Unused docker image" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

How can I get the Image successfully to the Docker Hub?

TIA

EDIT: Here is the docker-compose.yml file

version: '3'

services:
  authorize-service:
    build: ./authorizations
    container_name: authorize-service
    environment:
      - DB_IP=XXX.XX.XX.XX
      - DB_PORT=1521
      - DB_SID=TEST
      - DB_USER=xxxxxxx
      - DB_PASS=xxxxxxx
    ports:
      - 2700:5000
    networks:
      - kdcnetwork
  testtab-service:
    build: ./testtab
    container_name: testtab-service
    environment:
      - DB_IP=XXX.XX.XX.XX
      - DB_PORT=1521
      - DB_SID=TEST
      - DB_USER=xxxxx
      - DB_PASS=xxxxx
    ports:
      - 2800:5000
    networks:
      - kdcnetwork 
  website:
    build: ./website
    container_name: testtab-website
    links:
      - testtab-service 
    volumes:
      - ./website:/var/www/html
    ports:
      - 5000:80
    networks: 
      - kdcnetwork 
    depends_on:
      - testtab-service

networks:
  kdcnetwork:
    driver: bridge

You didn't provide docker-compose file so I cannot give very accurate answer but I can simply find that

Successfully tagged <docker_hub_id>object44_website:latest

differs from what you are trying to push:

docker push <docker_hub_id>/object:44

those 2 names must be the same.

Edit:

So you must change section in your docker-compose to following

website:
    build: ./website
    image: <docker_hub_id>/object:44

so docker-compose will build image <docker_hub_id>/object:44 and your docker push command should be able to push it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM