colima ignores template's DNS config
Description
I was getting these errors when trying to start a docker container:
failed to solve: redis:7: failed to resolve source metadata for docker.io/library/redis:7: failed to do request: Head "https://registry-1.docker.io/v2/library/redis/manifests/7": dial tcp: lookup registry-1.docker.io on 127.0.0.53:53: no such host
So I went into colima template, changed network.dns to 8.8.8.8, 8.8.4.4, then ran colima restart
# Network configurations for the virtual machine.
network:
# Custom DNS resolvers for the virtual machine.
#
# EXAMPLE
# dns: [8.8.8.8, 1.1.1.1]
#
# Default: []
dns:
- 8.8.8.8
- 8.8.4.4
I've run colima restart, colima stop, colima start, etc.
Nothing worked, I got exactly the same error message every time
failed to solve: redis:7: failed to resolve source metadata for docker.io/library/redis:7: failed to do request: Head "https://registry-1.docker.io/v2/library/redis/manifests/7": dial tcp: lookup registry-1.docker.io on 127.0.0.53:53: no such host
Which was surprising, because 127.0.0.53 is not in my /etc/resolv.conf, it's not in my scutil --dns, and it's not in my colima template! (I double checked several times, colima template was not getting reset or anything)
However, when I ran
colima stop
colima start --dns=8.8.8.8,8.8.4.4
The issue finally resolved.
I guess this means that colima template's DNS configurations are being ignored. Only the command-line flag works.
Version
colima version 0.8.0 git commit: 9c08cff339f087c0600d9d56af7b5fbcfe02e287
runtime: docker arch: aarch64 client: v27.3.1 server: v27.3.1 limactl version 1.0.1
Operating System
- [ ] macOS Intel <= 13 (Ventura)
- [ ] macOS Intel >= 14 (Sonoma)
- [ ] Apple Silicon <= 13 (Ventura)
- [X] Apple Silicon >= 14 (Sonoma)
- [ ] Linux
Output of colima status
INFO[0000] colima is running using macOS Virtualization.Framework
INFO[0000] arch: aarch64
INFO[0000] runtime: docker
INFO[0000] mountType: sshfs
INFO[0000] socket: unix:///Users/me/.colima/default/docker.sock
Reproduction Steps
- Change
dnsvalues incolima template colima restart
Expected behaviour
docker will use the template-specified DNS servers
Additional context
No response
Hey gereog,
I think you got confused about the purpose of colima template, or maybe it is not clear in the docs.
template edits the base configuration used only when you create a new VM, it will not change the current instance of Colima that you're running.
You could find the template file in ~/.colima/_templates/default.yaml.
So, if you create a new profile with colima start -P <profile-name> or delete and recreate the default instance , Colima will uses the template configuration.
To change the current instance of Colima you could either:
- Update
~/.colima/default/colima.yamlfile or, - Use the inline flags in
colima startas you did
I hope it is a little more clear than before :)
@dcitterio Why doesn't colima stop, colima template, colima start create a new vm, using the template?
You have to think that a "profile" is basically a VM that runs with its own configuration.
colima start runs the profile called default by default, and if the profile doesn't exist then it'll create it.
By using -P, you can choose to use another profile, which means that the profile will be created if it doesn't exist.
Every time you create a new profile, the VM will be created with the information that you configured in colima template.
If you run colima ls you can see every profile that you have.
colima stop simply stops the VM and nothing more
colima template allow you to customize ~/.colima/_templates/default.yaml file. It doesn't create or start anything
@dcitterio Thanks so much for the good explanation. Is the persistence of the default profile helpful to most people? Is there a way to make colima start delete and recreate the default profile every time?
Is the persistence of the default profile helpful to most people?
Absolutely. The VM contains all the docker images that you downloaded of built. For instance, if you need a Postgres DB for your local development, you don't want to download it from Docker Hub every time you start working with Docker.
Is there a way to make colima start delete and recreate the default profile every time?
Not directly. Still, I don't think that it is useful at all. What do you want to achieve by recreating the profile every time?
Is there a way to make colima start delete and recreate the default profile every time?
Not directly. Still, I don't think that it is useful at all. What do you want to achieve by recreating the profile every time?
I want to make it so that changes to the template will actually change the VM's configuration...
I would like it so that updating memory limits, storage limits, and DNS nameservers in the template will actually change the memory and storage limits and DNS nameservers of the docker VM.
I would like it so that updating memory limits, storage limits, and DNS nameservers in the template will actually change the memory and storage limits and DNS nameservers of the docker VM.
Got it.
In this scenario you need to use start command with the flags for the parameters that you want to change (like you did for the DNS),
or you could directly edit ~/.colima/default/colima.yaml configuration file.
@dcitterio if I edit ~/.colima/default/colima.yaml directly
- will all the docker images that I've downloaded and built get deleted?
- Will the settings actually take effect next time I run
colima startwith no flags?
will all the docker images that I've downloaded and built get deleted?
No, This happens only if you delete the VM with colima delete
Will the settings actually take effect next time I run colima start with no flags?
Correct. You can change almost everything. There only a couple of parameters that you cannot change once the VM is created, like enabling Rosetta. I don't recall the exact list to be honest, but I don't think you're going to bump into them ;)
Then, I don't understand why colima template wouldn't simply edit ~/.colima/default/colima.yaml, instead of opening an editor for changes that won't be applied until you delete your docker images.
template is a feature that is very useful if you want to run multiple instances at the same time. I'm using it usually when I want to create a k8s and run some destructive experiments.
template doesn't fit your use case for sure.
I also forgot that you can run colima start --edit which is exactly what you probably need.
I always edit the yml directly and I totally forgot of this option.
Why aren't colima start --edit and colima template the same file?