Mr.DevEng
Mr.DevEng

Reputation: 2421

Building of Docker image from Dockerfile making error "docker build" requires exactly 1 argument"

I am trying to build Docker image by using Jenkins pipeline script. When I am running the following code,

docker build -f Dockerfile -t spacestudykubernetes /var/lib/jenkins/workspace/cicd/pipeline

I added this command in inside Jenkins pipeline job shell script. There "cd" command will not work. Change directory not working in shell script. Because of that without changing directly, I gave the command with full path. According to your command it will work (after putting change directory) . I am trying to execute from cicd folder, not from pipeline folder. Dockerfile is resides in pipeline folder.

My Jenkins pipeline script

pipeline 
{
    agent any
    stages 
        {
            stage ('imagebuild')
                {
                    steps
                        {

sh 'docker build -f Dockerfile -t spacestudykubernetes /var/lib/jenkins/workspace/cicd/pipeline'

                        }
                }
        }
}

Error

I am getting the error like the following,

unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /var/lib/jenkins/workspace/cicd/Dockerfile: no such file or directory

I am not running from direct folder where Dockerfile is resides. My Dockerfile is resides in pipeline folder. That is my code checked out from SVN. And I am trying to run this command from cicd folder. And I gave the full path with -f argument.

Upvotes: 0

Views: 1224

Answers (1)

grapes
grapes

Reputation: 8646

You miss context directory at the end of command line. Usually it is simply .. This directory will serve as root for all paths in Dockerfile whenever you use ADD/COPY and also as a build context - meaning its content will be zipped and passed to docker daemon when build is executed.

cd /var/lib/jenkins/workspace/cicd/pipeline
docker build -f Dockerfile -t spacestudykubernetes .

Upvotes: 3

Related Questions