DEV Community

Cover image for Container image promotion across environments - Build Artifact

Container image promotion across environments - Build Artifact

Davide 'CoderDave' Benvegnù on November 14, 2019

When you use containers for your application, one of the things you need to think about is how to move (aka promote) the container images you gener...
Collapse
 
rulick76 profile image
Israel Rozen • Edited

Hi Davide,
I'm trying to use this approach but keep getting "reference does not exist" from deamon when trying to save the image to tar.
task: Docker@2
inputs:
containerRegistry: 'connectionForLabBuild'
repository: 'bapp.roadMapper'
command: 'build'
Dockerfile: '$(Build.SourcesDirectory)/bapp/bapp.roadMapper/Dockerfile'
tags: '$(Version)'

task: Docker@2
inputs:
containerRegistry: 'connectionForLabBuild'
repository: 'bapp.roadMapper'
command: 'save'
arguments: --output $(build.artifactstagingdirectory)/bapp.roadMapper.tar bapp.roadMapper:$(Version)

Collapse
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

The reference does not exist means that the image you are trying to export\save\use is not there.

In your case it is because you are using the "wrong" name.

When you build the image, you have 3 parts: the container registry, the name itself, and the tag

When you try and save it tho you use only name and tag. You have to specify the container registry name as well. The Docker task do not propagate it to the command

It should be something like:

task: Docker@2 
command: 'save' 
arguments: --output $(build.artifactstagingdirectory)/bapp.prime.roadMapper.tar $(ContainerRegistryName)/bapp.prime.roadMapper:$(primeVersion)
Enter fullscreen mode Exit fullscreen mode

And $(ContainerRegistryName) is a variable that you have to save or create somewhere before that

Collapse
 
rulick76 profile image
Israel Rozen

Thank you very much! it is working :)
Just wondering why do I have to to explicitly specify again the container registry if I'm specifying it it the task itself in the third line (the connectionForLabBuild service connection already define it)...

Thank a lot! I really appreciate !

task: Docker@2
inputs:
containerRegistry: 'connectionForLabBuild'
repository: 'bapp.roadMapper'
command: 'save'
arguments: --output $(build.artifactstagingdirectory)/bapp.roadMapper.tar bapp.roadMapper:$(Version)

Thread Thread
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

The reason for this is that save is not a command that is implemented in the task out of the box.

It works because what the task does is just appending the command part to the docker command, and then append the arguments. But the other fields, like container registry, are ignored because the task code "doesn't know what to do" with a command that is not being implemented.

Hope this clarifies :)

Collapse
 
risbochris profile image
risbochris

Thank you for your super article. Do you know how to set up if we want to deploy the image on on premise server with docker installed on it instead of a provider container registry like ACR ?

Collapse
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù • Edited

Thanks for the feedback :)

Well, even if you deploy to a local server on-prem, you would still need to use a container registry (either on-cloud or on-prem) to host your images that then docker can pull.

There is a "workaround" but I do not endorse it. When you have your imaged built and saved in the tar file using docker save, then you could copy that tar file to your target server and re-hydrate the image using docker load... this way you'd have the image directly on the server and you wouln't need a registry.
Once again, I do not recommend nor endorse this approach :)

Collapse
 
capdragon profile image
CaptDragon

This is the way!

Collapse
 
gustavgahm profile image
Gustav Gahm

This is brilliant and exactly what I was looking for. Thanks for sharing.

Collapse
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

Thanks for your comment :)

I've just published another post of the same series, to achieve the same thing but all with the YAML pipelines. Let me know what you think :)