FG
☁️ Cloud & DevOpsDocker

Docker compose pull doesn't respect local images

Freshabout 19 hours ago
Mar 14, 20260 views
Confidence Score95%
95%

Problem

During my searches I've seen this issue raised and closed a few times, but even using the latest build of docker-compose, this still doesn't behave the way I understand that it is expected to. Scenario: We're building a composed environment for our CI tests to run. We grab a database image, an api image, and a _local_ copy of the image containing application we are trying to test (it has been built in a previous CI step, and tagged with the build hash provided by our CI environment (CIRCLE_SHA1) docker-compose.yml [code block] The commands we run then are as follows: [code block] Actual Result: No matter what I do, docker compose always tries to pull my CIRCLE_SHA1 tagged version from docker hub. it doesn't exist there, I never want to push it (until it passes tests and is re-tagged as :latest and/or :release I have a unique tag CIRCLE_SHA1 which only exists inside the build environment, meaning no confusion for docker-compose when it tries to pull, and yet, it seems to try to fetch it anyway, and fail even though that exact tag exists locally. Expected Result: I'd expect the fact that there is no remote build tagged with CIRCLE_SHA1 to cause docker-compose to use the local copy it finds. I need to do pull, because I want everything else to be the latest. I'd suggest that if there is confusion where `image:` refers to a remote repository, then perhaps we could use `local:` instead, to reference a local image?

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Use Local Images in Docker Compose Without Pulling from Remote

Medium Risk

Docker Compose attempts to pull images from remote repositories if the image tag specified is not found locally. In this case, the CIRCLE_SHA1 tag is unique to the CI environment and does not exist in the remote repository, causing Docker Compose to fail when it tries to pull it. This behavior occurs because Docker Compose does not differentiate between local and remote images based on the tag alone.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Modify Docker Compose Configuration

    Update the docker-compose.yml file to include a build context for the local image instead of using the image tag directly. This will ensure that Docker Compose uses the local image without attempting to pull it from a remote repository.

    yaml
    version: '3.8'
    services:
      app:
        build:
          context: .
          dockerfile: Dockerfile
        image: your-image-name:${CIRCLE_SHA1}
      database:
        image: your-database-image:latest
  2. 2

    Build Local Image Before Running Docker Compose

    Ensure that the local image is built before running the docker-compose up command. This can be done in your CI pipeline by adding a step to build the image with the specified tag.

    bash
    docker build -t your-image-name:${CIRCLE_SHA1} .
  3. 3

    Run Docker Compose Without Pulling

    Run the docker-compose command with the --no-pull option to prevent Docker Compose from attempting to pull images from remote repositories. This ensures that only local images are used.

    bash
    docker-compose up --no-pull
  4. 4

    Verify Local Image Usage

    After running the docker-compose up command, verify that the local image was used by checking the running containers. You can use the command 'docker ps' to see the images being used by the containers.

    bash
    docker ps

Validation

Confirm that the application container is running with the expected local image by checking the output of 'docker ps'. The image ID should match the local image built with the CIRCLE_SHA1 tag.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

dockerdocker-composecontainerskind/question