Skip to content

feat: use docker-compose to parallel download images, fixes #7163 - #7217

Closed
AkibaAT wants to merge 3 commits into
ddev:mainfrom
AkibaAT:20250418_akibaat_parallel_docker_pull
Closed

AkibaAT wants to merge 3 commits into
ddev:mainfrom
AkibaAT:20250418_akibaat_parallel_docker_pull

Conversation

@AkibaAT

@AkibaAT AkibaAT commented Apr 18, 2025

Copy link
Copy Markdown
Contributor

The Issue

DDEV currently preloads all required images via individual docker pull commands.

How This PR Solves The Issue

This PR replaces this with a docker compose call, enabling parallel download of multiple images.

Manual Testing Instructions

Remove DDEV images from local Docker
Run ddev debug download-images

Automated Testing Overview

Release/Deployment Notes

@github-actions

github-actions Bot commented Apr 18, 2025 •

Copy link
Copy Markdown

@AkibaAT
AkibaAT force-pushed the 20250418_akibaat_parallel_docker_pull branch from 01efd41 to 6936196 Compare April 18, 2025 23:16
@AkibaAT
AkibaAT force-pushed the 20250418_akibaat_parallel_docker_pull branch from 6936196 to e3e9ebf Compare April 19, 2025 17:44

@rfay rfay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you're not done with this yet, but I think it should be using ComposeCmd() to do its work.

@AkibaAT

AkibaAT commented Apr 21, 2025

Copy link
Copy Markdown
Contributor Author

I saw #7085 after this, so I'll likely rework this to cover that as well.

@rfay

rfay commented Apr 21, 2025

Copy link
Copy Markdown
Member

I'm not entirely sure this idea doesn't already solve #7085 since you're using .ddev/.ddev-docker-compose-full.yaml

@AkibaAT

AkibaAT commented Apr 21, 2025

Copy link
Copy Markdown
Contributor Author

This draft doesn't yet, it's currently still the same image list as before. But yeah, using the docker compose file instead would be the goal.

@stasadev

stasadev commented Apr 21, 2025 •

Copy link
Copy Markdown
Member

Thank you, I didn't know you could use a buffer for this.

This is cool, but it's a little confusing to see errors (or warnings, as they don't stop the ddev start) when I already have the images and disconnect from the Internet:

$ ddev start
...
[+] Pulling 5/5
 ✘ ddev-ddev-ssh-agent-v1.24.4 Error      Get "https://registry-1.docker.io/v2/":...                                    0.1s 
 ✘ ddev-ddev-webserver-v1.24.4 Error      Get "https://registry-1.docker.io/v2/":...                                    0.1s 
 ✘ ddev-ddev-traefik-router-v1.24.4 Error Get "https://registry-1.docker.io/...                                         0.1s 
 ✘ busybox-stable Error                   Get "https://registry-1.docker.io/v2/": dial tcp: lo...                       0.1s 
 ✘ ddev-ddev-utilities Error              Get "https://registry-1.docker.io/v2/": dial tc...                            0.1s 
Error response from daemon: Get "https://registry-1.docker.io/v2/": dial tcp: lookup registry-1.docker.io: Temporary failure in name resolution
Unable to pull Docker images: failed to pull Docker images: exit status 1 
Building project images....
Project images built in 2s.
...

@AkibaAT

AkibaAT commented Apr 21, 2025 •

Copy link
Copy Markdown
Contributor Author

Hmmm... alright, I had not considered the behaviour when offline. Testing this, the current version handles this better, although the debug log claim isn't quite right either, claiming that the images got pulled.

(base) ➜  d11 DDEV_DEBUG=true ddev debug download-images
2025-04-21T22:34:54.541 Pulled image for ddev/ddev-webserver:v1.24.4
2025-04-21T22:34:54.568 Pulled image for busybox:stable
2025-04-21T22:34:54.583 Pulled image for ddev/ddev-utilities
2025-04-21T22:34:54.602 Pulled image for ddev/ddev-ssh-agent:v1.24.4
2025-04-21T22:34:54.625 Pulled image for ddev/ddev-traefik-router:v1.24.4
2025-04-21T22:34:54.672 Pulled ddev/ddev-dbserver-mariadb-10.11:v1.24.4
Successfully downloaded DDEV images

Properly handling this, we'd either need to detect what images are already present and not pull them at all (what about updates for moving targets like busybox:stable then?), or maybe detect if the user is currently offline, and provide a separate error message for that case. Or suppress all direct output and instead parse the results? That would look like it's hanging though, without some alternate output, like during the image build process.

There is a --ignore-pull-failures flag according to https://docs.docker.com/reference/cli/docker/compose/pull/, but that would then ignore any sort of pull error, also for images that the user doesn't already have.

@stasadev

Copy link
Copy Markdown
Member

what about updates for moving targets like busybox:stable then?

We don't have this behavior right now, because we check for the existing image, and pull nothing if it exists (but I would like it to do an actual pull, so this is good.)

maybe detect if the user is currently offline, and provide a separate error message for that case.

Good idea, and we have a globalconfig.IsInternetActive() function for this check.

@rfay

rfay commented Apr 21, 2025

Copy link
Copy Markdown
Member

I'm not sure how often busybox changes, but there's any reason to actually use busybox:stable, it's just a random utility image. We could use 1.37.0, for example, instead of stable

@AkibaAT

AkibaAT commented Apr 23, 2025

Copy link
Copy Markdown
Contributor Author

Changed the logic to pull in all project images if there's a valid project context, and otherwise falls back to the base list (minus MariaDB).
Internet connection check added, outputs a warning Internet connection not detected, skipping Docker image pull. Some images may be missing. if there's no connection, but doesn't interrupt the execution.

@rfay rfay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this doesn't just use existing ComposeCmd (with pull instead of exec, just like here:

stdoutResult, stderrResult, err = dockerutil.ComposeCmd([]string{app.DockerComposeFullRenderedYAMLPath()}, exec...)

That should be super trivial, with the code already written. That would pull all images in the "full" yaml

@AkibaAT

AkibaAT commented Apr 23, 2025

Copy link
Copy Markdown
Contributor Author

Try to run a pull on the full yaml in the shell.

Example: docker compose -f .ddev-docker-compose-full.yaml pull
Result:

 ✔ redis Pulled                                                                                                                                                                                                                                                                    1.4s
 ! web Warning  failed to resolve reference "docker.io/ddev/ddev-webserver:v1.24.4-fvn-li-built": docker.io/ddev/ddev-webserver:v1.24.4-fvn-li-built: not found                                                                                                                    1.3s
 ! db Warning   failed to resolve reference "docker.io/library/postgres:17-fvn-li-built": docker.io/library/postgres:17-fvn-li-built: not found                                                                                                                                    1.3s
WARNING: Some service image(s) must be built from source by running:
    docker compose build web db
2 errors occurred:
        * Error response from daemon: failed to resolve reference "docker.io/ddev/ddev-webserver:v1.24.4-fvn-li-built": docker.io/ddev/ddev-webserver:v1.24.4-fvn-li-built: not found
        * Error response from daemon: failed to resolve reference "docker.io/library/postgres:17-fvn-li-built": docker.io/library/postgres:17-fvn-li-built: not found

@AkibaAT

AkibaAT commented Apr 23, 2025

Copy link
Copy Markdown
Contributor Author

Additionally, even if we would take the full YAML and manipulate it the same way that FindAllImages does, we'd only be pulling 2 images by default, the one for web, and the one for the db, missing all the images that are required outside the project's full YAML:

  • busybox
  • ddev/ddev-ssh-agent
  • ddev/ddev-traefik-router
  • ddev/ddev-utilities

Which is why I'm building a YAML based on FindAllImages, to get all of them together.

@rfay

rfay commented Apr 23, 2025

Copy link
Copy Markdown
Member

IMO it would be better to do the one-off images separately, super easy, already done that way. There's also the issue of things like codespaces/gitpod, where the router and probably ddev-ssh-agent don't need to be pulled. IMO ddev-utilities doesn't actually ever need to be pulled until needed. (Now that I think about it, we could use ddev-utilities everywhere we use busybox and drop busybox)

@AkibaAT

AkibaAT commented Apr 23, 2025

Copy link
Copy Markdown
Contributor Author

The one-off images are pulled in a separate function in the current release version, true, but that's also happening at every ddev start, as individual docker pull calls, via PullBaseContainerImages().
Then, a little further down the start function, the project images are being pulled in, as individual docker pull calls, via app.PullContainerImages(). I saw no functional reason for this split, but perhaps I overlooked a good reason for keeping it.
Moving from individual docker pull calls, which run in succession, to docker compose pull, which runs in parallel, is the main motivation for this PR.
One main difference to the current release version is that this PR doesn't skip the pull attempt for images that already exist. But this was confirmed as a good thing by @stasadev:

We don't have this behavior right now, because we check for the existing image, and pull nothing if it exists (but I would like it to do an actual pull, so this is good.)

@rfay rfay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the .ddev/.ddev-docker-compose-full.yaml using ComposeCmd, and then an extra pull for the one-off's.

Thanks! Sorry I didn't give more guidance on this to start with.

Comment thread pkg/ddevapp/ddevapp.go
func PullBaseContainerImages() error {
images := []string{ddevImages.GetWebImage(), versionconstants.BusyboxImage, versionconstants.UtilitiesImage}
images = append(images, FindNotOmittedImages(nil)...)
// Create docker-compose.yaml file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I object to this, don't want another random file being created, and certainly not one with a generic name like this.

@AkibaAT AkibaAT Apr 23, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A pull on docker-compose-full doesn't work, as demonstrated further up. There is a --ignore-buildable flag for compose, but that would not leave much to be pulled, as that just skips right over the web and db services.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The temporary YAML gets put into a temp directory: tmpDir, err := os.MkdirTemp("", "ddev-pull-images-"). I'd prefer to work completely in-memory, like an in earlier version of this PR, but dockerutil.ComposeCmd, which contains logic we do want to use here, requires a file.

@rfay

rfay commented Apr 23, 2025

Copy link
Copy Markdown
Member

Just a note here on why we use docker-compose and why we use a private version of it.

  • Early on in compose v2 they broke lots of things with every release, to where we just had to "vendor" it to provide any reliability.
  • If we were to use docker compose instead of our private docker-compose then we'd be using the plugin that the user provided, which we have no control of.
  • Our overall strategy is not to make changes to the user's machine (like requiring specific versions of docker cli or compose plugin). In general, we try to have the user explicitly make any changes of this type, for example, with mkcert -install. The so-far unavoidable exception is editing the hosts file when people can't resolve *.ddev.site or use a non-ddev.site URL.

@AkibaAT AkibaAT closed this Apr 23, 2025
@AkibaAT
AkibaAT deleted the 20250418_akibaat_parallel_docker_pull branch April 23, 2025 14:34
@stasadev

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants