Skip to content

Commit

Permalink
Make the Nerdctl dockerresolver module happy.
Browse files Browse the repository at this point in the history
If a user is logged in, but there's no auths["https://index.docker.io/v1/"]
entry in the root's `.docker/config.json` file, the docker-resolver
code will get confused.

So here's how to get into the state that this change fixes:

* Factory-reset or create a clean state
* Start up RD in docker mode (with k8s off to speed things up)
* docker login
* Switch to containerd
* nerdctl pull busybox

Without this change, you'll see an error along the lines of

    FATA[0000] expected ac.ServerAddress ("") to be "https://index.docker.io/v1/"

With this change, nerdctl should proceed as usual.

Note that with no `auths` field in `/root/.docker/config.json`, running
`docker login` doesn't add it, but running `nerdctl login` does.

And if the user is logged out when the code is run, `nerdctl logout`
changes the field to `auths: {}`, but the behavior is the same for
logged out users, whether auths is empty or has an entry for
index.docker.io.

The real error here is that when a `configsStore` field is given in
`.docker/config.json`, the `auths` field should be ignored. Docker is
ignoring it, nerdctl isn't.

Upstream issue: github.com/containerd/nerdctl/pull/1315 with
PR 1315, but some integration tests are failing (looks like due to
flakes) and I don't see a straightforward way to provide unit tests.

Signed-off-by: Eric Promislow <epromislow@suse.com>
  • Loading branch information
ericpromislow committed Aug 12, 2022
1 parent ab7850e commit 4ef3977
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/backend/lima.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,13 @@ CREDFWD_URL='http://${ hostIPAddr }:${ stateInfo.port }'
existingConfig = {};
}
merge(existingConfig, defaultConfig);
if (this.cfg?.containerEngine === ContainerEngine.CONTAINERD) {
// Fix error 2689 - nerdctl breaks when it gets confused by an empty ServerAddress
const fixedConfig = { auths: { 'https://index.docker.io/v1/': {} } };

merge(fixedConfig, existingConfig);
existingConfig = fixedConfig;
}
await this.writeFile(ROOT_DOCKER_CONFIG_PATH, jsonStringifyWithWhiteSpace(existingConfig), 0o644);
} catch (err: any) {
console.log('Error trying to create/update docker credential files:', err);
Expand Down

0 comments on commit 4ef3977

Please sign in to comment.