skip to Main Content

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


  1. 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:

    docker pull eclipse-temurin:21.0.4_7-jre-ubi9-minimal
    

    Once you have the image cached locally, you can build the Docker container without checking for updates or pulling images:

    docker compose up -d --build --pull never
    
    Login or Signup to reply.
  2. 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 to dockerhub

    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_here
    Having said that when you don’t have access to internet, You can try the following commands.

    1. Try loading the image from the local cache before running your Docker build

      $ docker load < [/path/to/your/image.tar]

    2. 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

    3. 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 reference

    4. You 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

    5. To be prevent Docker daemon settings from reaching out to the Docker Hub, it is advisable you edit the config file
      cd /etc/docker/daemon.json you should see a json file adjust accordingly use the json file below as a guide.

       {
         "disable-legacy-registry": true,
         "registry-mirrors": [],
         "insecure-registries": []
       }
      
    6. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search