hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.01k stars 4.42k forks source link

Docker rebuild existing image due to incorrect check #13384

Open eszense opened 2 months ago

eszense commented 2 months ago

Vagrant is always rebuilding existing image on my machine.

Likely this is caused by a bug here. Which attempts search for an existing image ID from the command docker images -q https://github.com/hashicorp/vagrant/blob/d8fdc500b76c840cdeaa69869d0c000530b036b3/plugins/providers/docker/driver.rb#L127-L130 However, docker images -q only outputs the short (truncated) image ID without the --no-trunc argument, hence there was no match for the full image ID cached on .vagrant/machines/default/docker/docker_build_image

Docker output

$docker image ls -q
302d1cb135c3
...

$docker image ls -q --no-trunc
sha256:302d1cb135c325ea41b8e1a748af44119be535ee88431274a2d4d8265b45ae0d
...

File content

.vagrant/machines/default/docker/docker_build_image

302d1cb135c325ea41b8e1a748af44119be535ee88431274a2d4d8265b45ae0d

Debug output

$vagrant up
Bringing machine 'default' up with 'docker' provider...
==> default: Creating and configuring docker networks...
==> default: Build image no longer exists. Rebuilding...
==> default: Building the container from the named Dockerfile: Dockerfile...

Expected behavior

Skip rebuild when image already exists

Vagrant version

Vagrant 2.4.1

Host operating system

macOS Sonoma ARM64 Docker version 24.0.6

Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.provider "docker" do |d|
    d.build_dir = "."
    d.dockerfile = "Dockerfile"
    d.remains_running = false
  end
end