I have 2 containers defined in docker-compose.yml and a Dockerfile for my app. I want to be able to build the image locally even when I don’t have internet connection. Looking at docker compose up --help
, I see the --pull never
option. But it’s still trying to check for updates of the base image I’m using in my Dockerfile.
So the command I’m running is docker compose up -d --build --pull never
And the error is:
failed to solve: eclipse-temurin:21.0.4_7-jre-ubi9-minimal: failed to resolve source metadata for docker.io/library/eclipse-temurin:21.0.4_7-jre-ubi9-minimal: failed to do request: Head "https://registry-1.docker.io/v2/library/eclipse-temurin/manifests/21.0.4_7-jre-ubi9-minimal": dial tcp: lookup registry-1.docker.io on {IP}: no such host
2
Answers
Before going offline, ensure the base image and any dependencies required for the build are pulled and cached locally. You can do this by running:
Once you have the image cached locally, you can build the Docker container without checking for updates or pulling images:
From the error you have provided I am guessing the issue is that
Docker
is is still trying to authenticate or verify metadata by making a request to the Docker Hub registry, which is uncommon if you look at what the metadata.json contains look at this link docs_on_metadata_json_docker you would understand why the docker image still make reference todockerhub
Sometimes it is always good practise to look at the
Docker file
of image you are installing, this gives you more insights to the problem for example Search_Dockerfile_of_your_image_hereHaving said that when you don’t have access to internet, You can try the following commands.
Try loading the image from the local cache before running your Docker build
$ docker load < [/path/to/your/image.tar]
Use a docker save and docker load Workflow:
$ docker save -o eclipse-temurin-21.0.4.tar eclipse-temurin:21.0.4_7-jre-ubi9-minimal
Store the Image Locally and Transfer the
tar-file
to your offline environment(disconnet-internet-access) where you can load it from:$ docker load -i eclipse-temurin-21.0.4.tar
use this link as referenceYou can then go ahead to disable docker buildkit using the following command.
$DOCKER_BUILDKIT=0 docker build -t your_app .
OR with docker-compose
DOCKER_BUILDKIT=0 docker compose up -d --build --pull never
To be prevent
Docker daemon settings
from reaching out to the Docker Hub, it is advisable you edit theconfig file
cd
/etc/docker/daemon.json
you should see ajson file
adjust accordingly use thejson file
below as a guide.Finally
$ systemctl restart docker
In
hindsight
if you are going to be doing this kinda of set-up I suggest setting local-repo use this link to guide you or any useful resource out there.