Working with Docker Registries
How to push, pull and tag Docker images in Codefresh pipelines
Codefresh contains first class Docker registry support. This means that you don’t need to manually write
docker login and
docker pull/push commands inside pipelines. You use instead declarative YAML and all credential configuration is configured centrally once.
Pulling Docker images
Pulling Docker images in Codefresh is completely automatic. You only need to mention a Docker image by name and Codefresh will automatically pull it for you and use it in a pipeline.
Pulling public images
To pull a public image from Dockerhub or other public registry you simply mention the name of the image and tag that you want to use. For example:
CollectAllMyDeps: title: Install dependencies image: python:3.6.4-alpine3.6 commands: - pip install .
The image will also be cached in the image cache without any other configuration.
Codefresh will also automatically pull for you any images mentioned in Dockerfiles (i.e. the
FROM directive) as well as service containers.
Pulling private images
To pull a private image from the internal Codefresh registry, again you mention the image by name and tag. In order for Codefresh to understand that you are talking about a private image you need to prepend the
r.cfcr.io prefix along with your username.
The full image name will be in the form:
You can find the full name of any docker image by visiting your registry and looking at the URL field of any tag:
Note however that because the Codefresh registry is fully automated (successful pipelines automatically push there), you very rarely need to pull private images by name as you can simply mention their step name, as explained in the next section.
Pulling images that were just built in the same pipeline
The Codefresh private registry is deeply integrated into Codefresh pipelines and pulls/pushes to it happen in a transparent manner. In most scenarios (such as unit tests) you mention private Docker images that were also built in the same pipeline.
In this pipeline Codefresh:
- Checks out source code with the git-clone step
- Builds a docker image that gets named
- Automatically pushes the image to the private docker registry (notice the lack of
- In the next step automatically pulls that image and runs
python setup.py testinside it. Again notice the lack of
The important line here is the following:
This says to Codefresh “in this step please use the Docker image that was built in the step named
You can see the automatic pull inside the Codefresh logs.
Therefore in most cases you don’t need to specifically mention
r.cfcr.io inside your pipelines (only in Dockerfiles).
Pulling images from external registries
To pull images from external registries you need to connect them first to Codefresh. This happens via the external registry configuration screen. The credentials are defined centrally there and then all pipelines are credential free.
To pull an image from an external registry, you simply mention the image by name as shown in the previous sections. Codefresh will use the domain prefix of each image to understand which integration it will use. It will then take care of all
docker login and
docker pull commands on its own behind the scenes.
Codefresh will automatically login to each registry using the credentials you have defined centrally and pull all the images. The same thing will happen with Dockerfiles that mention any valid docker image in their
Pushing Docker images
Pushing to the built-in registry is completely automatic. All successful build steps automatically push the private Docker registry without any extra configuration.
To push to an external registry you only need to know how this registry is linked into Codefresh and more specifically what is unique name of the integration. You can see that name by visiting your integrations screen or asking your Codefresh administrator.
Once you know the registry identifier you can use it an push step by mentioning the registry with that name:
candidatefield of the push step mentions the name of the build step (
build_image) that will be used for the image to be pushed
- The registry is only identified by name (i.e.
azure-demo). The domain and credentials are not part of the pipeline (they are already known to Codefresh by the Docker registry integration)
You can also override the name of the image with any custom name. This way the push step can choose any image name regardless of what was used in the build step.
Here the build step is creating an image named
my-app-image:master but the push step will actually push it as
For more examples such as using multiple tags, or pushing in parallel see the push examples
Promoting Docker images
Apart from building and pushing a brand new docker image, you can also “promote” a docker image by copying it from one registry to another. This is accomplished by specifying an existing image in the
candidate field of the push step.
In the example above we promote an image from the internal Codefresh registry to an external Azure registry (which is already setup as
You can also “promote” docker images within the same registry by simply creating new tags. For example:
In the example above the image
my-azure-registry.azurecr.io/kostis-codefresh/my-python-app:1.2.3 is re-tagged as
my-azure-registry.azurecr.io/kostis-codefresh/my-python-app:prod. A very common pattern is to mark images with a special tag such as
prod after the image has been deployed successfully.