IT-Sheriff
IT-Sheriff

Reputation: 164

How to use different base path while running docker pull?

We are storing our docker images in various registries based on environment. For example dev docker images are being stored in https://dev-artifactory/docker-repository/centos:latest, prod docker images are being stored in https://prod-artifactory/docker-registry/centos:latest.

We are using different artifactory instances because of connectivity challenges.

We want to specify the base path of docker images (dev-artifactory or prod-artifactory ) in some kind of environment variable so that all we have to run is docker pull centos:latest and based on environment type, it automatically detects dev-artifactory or prod-artifactory.

Upvotes: 0

Views: 1407

Answers (3)

davidxxx
davidxxx

Reputation: 131486

The Docker registry differs from nexus or npm registries in a way where as you noticed pull/push operations have to prefix the image with the registry hostname to work as expected.
So using private registries with different hostnames within the same company makes the configuration/day-to-day tasks bigger, error-prone and less standard.
If I can avoid that, I avoid that.

If I really need to use more than one registy, the BMitch advises are those that I would apply.

We are using different artifactory instances because of connectivity challenges.

In that scenario, I would use a scalling solution rather than distinct registries with distinct configurations.
Private docker registries can be loadbalanced.

High Availability and Scaling

It is possible to run multiple containers against the same storage back-end for performance and availability reasons.

Here is an example using a shared s3 storage back-end, Redis cache and MySQL search database (all should be common across containers for consistency)

docker run \
         -e SETTINGS_FLAVOR=s3 \
         -e AWS_BUCKET=mybucket \
         -e AWS_KEY=myawskey \
         -e AWS_SECRET=myawssecret \
         -e CACHE_REDIS_HOST=redis.host \
         -e CACHE_REDIS_PORT=6379 \
         -e CACHE_REDIS_DB=1 \
         -e CACHE_LRU_REDIS_HOST=redis.host \
         -e CACHE_LRU_REDIS_PORT=6379 \
         -e CACHE_LRU_REDIS_DB=0 \
         -e AWS_REGION=us-east-1 \
         -e SEARCH_BACKEND=sqlalchemy \
         -e SQLALCHEMY_INDEX_DATABASE=mysql://user:[email protected]/db_name
         -p 5000:5000 \
         registry

It is an AWS example but you can do without of course.

As a side note, companies where I worked with Docker, a private registry was used (potentially load-balanced) with a single hostname prefix and we distinguish snapshot and release versions thanks to the image version (+ image labels) such as :

my-company/foo-app:1.0-SNAPSHOT  LABEL env="dev"

my-company/foo-app:1.0           LABEL env="prod"

Upvotes: 0

BMitch
BMitch

Reputation: 264761

It cannot be done reliably for the low level docker CLI. Without a registry prefix, docker and other container runtimes assume you want to use Docker Hub. You could theoretically configure the docker engine with a registry mirror setting, but this is error prone (any pull failure from your local registry will fall back to docker hub), doesn't apply to push commands, and results in a Dockerfile that builds differently depending on what node it builds.

Therefore in the docker CLI, you are required to include that prefix with commands like:

docker pull dev-artifactory/docker-repository/centos:latest

Instead of trying a hack like setting the registry mirror, I'd recommend setting this in the various configuration files used to automatically build and deploy containers. At build time, this is done as an ARG value in the Dockerfile, before the first FROM line so you can use it when specifying images inside your builds. E.g.

ARG REGISTRY=dev-artifactory/docker-repository
FROM ${REGISTRY}/centos:latest

And for running containers, use a variable inside the docker-compose.yml file. E.g.

version: 2
services:
  app:
    image: ${REGISTRY:-dev-artifactory/docker-repository}/app:latest
    ....

Similarly with kubernetes, prefixing a registry would be done with a tool the processes the yml files, e.g. envsubst, helm, or kustomize.

Upvotes: 3

Simon Danninger
Simon Danninger

Reputation: 458

you could specify full path like:

docker pull dev-artifactory/docker-repository/centos:latest
docker pull prod-artifactory/docker-registry/centos:latest

mind: those should be rigistries.

Upvotes: -1

Related Questions