0

I'm building and pushing a docker image to ecr as part of a jenkins pipeline.

 environment { registry = "11111111111.dkr.ecr.eu-west-2.amazonaws.com/bar" registryCredential = 'ecr-creds' stages { stage('Docker Build') { steps { dir('assets/'){ script { dockerImage = docker.build registry } } } } stage('Docker Deploy') { steps{ script { docker.withRegistry("https://" + registry, "ecr:eu-west-2:" + registryCredential ) { dockerImage.push() } } } } 

However, I need to add the flag --network host as part of my docker build argument as its the only way I'm able to successfully build the image.

Doing this sh "docker build -t $registry . --network host" works, but then the Docker Deploy stage fails with a No such property: dockerImage error which is understandable as dockerImage isn't defined anymore.

Is there a way to add the --network host flag?

1 Answer 1

2

Using Docker with Pipeline in the Jenkins documentation notes:

It is possible to pass other arguments to docker build by adding them to the second argument of the build() method. When passing arguments this way, the last value in the that string must be the path to the docker file and should end with the folder to use as the build context)

So, you should be able to write:

stage('Docker Build') { steps { dockerImage = docker.build(registry, '--network=host assets') } } 

(You shouldn't usually need host networking in Docker, especially during the image-build phase, but if you're working around a network-configuration issue it can be a little tricky to figure out.)

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I'm having to work around a bit of a network config issue, hence the need for the flag. Thanks a lot for your help. I was able to get it to work by amending your suggestion to dockerImage = docker.build(registry, '--network=host .')

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.