0

I'm an issue finding any proper example of how to build, register, and run a docker image via a jenkinsfile for a Pipeline job. Here is what I have so far:

node {
    def myService

    stage('Checkout Project') {
        checkout scm
    }

    stage('Build Binary') {
        sh "mvn package -f pom.xml -Dmaven.test.skip=true"
    }

    stage('Build Image') {
        sh "pwd"
        myService = docker.build('myService -f ${pwd}/Dockerfile')
    }

    stage('Test Image') {
        sh "echo Tests Passed :)"
    }

    stage('Run uShip Docker Container') {
        myService.run()
    }
}

first issue I'm is that when the docker.build() fires, it cannot find my docker file which I find odd because the command runs the same directory of the Dockerfile. Next I cannot any consistent example of how to register, push, and run the image. Any help would be greatly appreciated!

UPDATE: Well fixed the issue with docker not being able to locate the docker file. It was a naming issue; my docker file was names "DockerFile" instead of "Dockerfile". Renamed and it worked, but now I'm getting another error:

Invalid repository name (myService), only [a-z0-9-_.] are allowed

Not sure what's this is referring to.

UPDATE: In addition to my initial question, does a docker-compose file have to be of type .yml or can it be a .properties file?

Joseph Freeman
  • 1,644
  • 4
  • 24
  • 43
  • docker-compose fila can have extension yml, or yaml. The repository name is incorrect - the letters which you can use are enlisted in brackets. – h__ Jun 09 '17 at 20:00

2 Answers2

1

The docker.build command expects a image name with an optional tag as parameter.

From the documentation:

Name components may contain lowercase letters, digits and separators. A separator is defined as a period, one or two underscores, or one or more dashes.

So the name myService is invalid because of the uppercase S

Also, the docker.build command looks for a Dockerfile on the same location, so you don't need the -f ${pwd}/Dockerfile on the parameter

docker.build('myservice') should work

Raquel Guimarães
  • 957
  • 1
  • 12
  • 18
0

Invalid repository name (myService), only [a-z0-9-_.] are allowed

Do not use uppercase when naming your docker image. This is a standard.

does a docker-compose file have to be of type .yml or can it be a .properties file?

A docker-compose file should always be a yaml file.

john
  • 425
  • 4
  • 12
  • So does it have to be of type .yml or can it optionally be a .properties file? reason I ask is because I prefer the .properties syntax of yaml syntax. So if docker only supports yaml then I'll just use yaml. – Joseph Freeman Jun 12 '17 at 16:07