Using images built with CircleCI in multiple jobs

docker

#1

One of the things I did with the 1.0 workflow was build and subsequently test a production container (hitting some endpoints with curl for basic responses) before we pushed it live. With the 2.0 update, it looked like I might be able to achieve this across 2 jobs (build and test) using the image created using the remote docker daemon; however, according to the documentation, only images in public repositories can be used unless you run through the steps to pull from a private registry. Even if I wanted to pull from a private registry, this would require me to push and then pull all just to have the fresh image available in the next job of the same workflow. I was really hoping to be able to use what I had built in the first job as the image for another job in the workflow, primarily because I could supply things like environment variables and test commands to it in a very clean fashion compared to doing it all as a long series of more arduous (and messy) commands from the docker client container.

Is there any way for me to pick up and use an image built by CircleCI as the container for another job in the same workflow? Or will I have to do all of the build/test/push in a single job using a container that is capable of all of them, due to access to built images not persisting across jobs?

Thanks in advance, and nice work on 2.0


Best practice for custom/private docker containers?
#2

I have the same question. Any answer on this?


#3

I believe Docker Layer Caching allows you to use an image built in the previous job. However layer caching is not enabled for everyone. I had to request the feature via support. After I got it enabled I could run the image in later jobs.

(Caveat: For me, the cache sometimes failed and I am talking to support now. Meanwhile I push the image to the registry and pull it in the later jobs.)


#4

Thanks for this question. We built ‘workspaces’ to help in this scenario: https://circleci.com/blog/how-to-build-a-docker-image-on-circleci-2-0/

Also it’s now possible to use private images: Allow Using Private Docker Images


#5

@baxang I think caching re-use is not guaranteed - that’s why I think you get the occasional failure? Or did you ever get it resolved?


#6

@tom is there a definitive answer somewhere on how to use workspaces to re-use docker images in downstream jobs? The blog post you refer to uses cache rather than workspaces.


#7

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.