question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle empty or invalid `$HOME/.docker/config.json` gracefully

See original GitHub issue

Reference: https://issues.apache.org/jira/browse/INFRA-22697

Apparently testcontainers requires $HOME/.docker/config.json to be a valid JSON file.

touch ~/.docker/config.json
// lauch some test containers tests will now fail

echo '{}' > ~/.docker/config.json
// lauch some test containers tests will now succeeds

rm ~/.docker/config.json
// lauch some test containers tests will now succeeds

The problem is that I have little control on the content of this file as provided on the ASF CI environments. I would like testcontainers to ignore it as missing when its content is missing…

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
chibenwacommented, Jan 5, 2022

Handle empty $HOME/.docker/config.json gracefully

I wonder if it should not be rather Handle invalid $HOME/.docker/config.json gracefully.

As this config is apparently only used to discover private registry if invalid we could adopt a lenient beaviour and behave as if there was no such file (maybe with a log)

This is what docker CLI does:

$ echo "bad" > ~/.docker/config.json
$ cat ~/.docker/config.json
bad
$ docker ps
WARNING: Error loading config file: /home/interview1/.docker/config.json: invalid character 'b' looking for beginning of value
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
...

You could see that even if it complains, the invalid file did not prevent the docker CLI from working normally…

I think such a behaviour would be less specific to my use case but benefit the whole community.

1reaction
dplavciccommented, Jun 21, 2022

Hi @chibenwa, can you still reproduce this if invalid config.json file is provided?

Reference: https://issues.apache.org/jira/browse/INFRA-22697

Apparently testcontainers requires $HOME/.docker/config.json to be a valid JSON file.

touch ~/.docker/config.json
// lauch some test containers tests will now fail

echo '{}' > ~/.docker/config.json
// lauch some test containers tests will now succeeds

rm ~/.docker/config.json
// lauch some test containers tests will now succeeds

The problem is that I have little control on the content of this file as provided on the ASF CI environments. I would like testcontainers to ignore it as missing when its content is missing…

I have tried to reproduce it locally (testcontainers version 1.17.2) by executing test provided here, but I can’t (not sure if I’m doing something wrong, or if the “issue” is fixed) 🤔

touch ~/.docker/config.json
// lauch some test containers tests will now fail <-- this is no longer true

21:13:07.484 [main] DEBUG org.testcontainers.dockerclient.AuthDelegatingDockerClientConfig - Delegate call to effectiveAuthConfig failed with cause: 'Failed to parse docker configuration file'. Resolution of auth config will continue using RegistryAuthLocator.
21:13:07.486 [main] DEBUG org.testcontainers.utility.RegistryAuthLocator - Looking up auth config for image: testcontainers/ryuk:0.3.3 at registry: https://index.docker.io/v1/
21:13:07.487 [main] DEBUG org.testcontainers.utility.RegistryAuthLocator - RegistryAuthLocator has configFile: /qwe/user/.docker/config.json (exists) and commandPathPrefix:
21:13:07.487 [main] INFO org.testcontainers.utility.RegistryAuthLocator - Failure when attempting to lookup auth config. Please ignore if you don't have images in an authenticated registry. Details: (dockerImageName: testcontainers/ryuk:0.3.3, configFile: /qwe/user/.docker/config.json. Falling back to docker-java default behaviour. Exception message: No content to map due to end-of-input
 at [Source: /qwe/user/.docker/config.json; line: 1, column: 0]
21:13:07.489 [main] DEBUG org.testcontainers.utility.RegistryAuthLocator - No matching Auth Configs - falling back to defaultAuthConfig [AuthConfig{username=null, password=blank, auth=blank, email=null, registryAddress=https://index.docker.io/v1/, registryToken=blank}]
21:13:07.490 [main] DEBUG org.testcontainers.dockerclient.AuthDelegatingDockerClientConfig - Effective auth config [AuthConfig{username=null, password=blank, auth=blank, email=null, registryAddress=https://index.docker.io/v1/, registryToken=blank}]
2
echo '{}' > ~/.docker/config.json
// lauch some test containers tests will now succeeds <-- this is true

21:16:06.512 [main] DEBUG org.testcontainers.utility.RegistryAuthLocator - Looking up auth config for image: testcontainers/ryuk:0.3.3 at registry: https://index.docker.io/v1/
21:16:06.514 [main] DEBUG org.testcontainers.utility.RegistryAuthLocator - RegistryAuthLocator has configFile: /qwe/user/.docker/config.json (exists) and commandPathPrefix:
21:16:06.514 [main] DEBUG org.testcontainers.utility.RegistryAuthLocator - registryName [https://index.docker.io/v1/] for dockerImageName [testcontainers/ryuk:0.3.3]
21:16:06.515 [main] DEBUG org.testcontainers.utility.RegistryAuthLocator - No matching Auth Configs - falling back to defaultAuthConfig [null]
21:16:06.515 [main] DEBUG org.testcontainers.dockerclient.AuthDelegatingDockerClientConfig - Effective auth config [null]
rm ~/.docker/config.json
// lauch some test containers tests will now succeeds <-- this is true

21:17:47.531 [main] DEBUG org.testcontainers.utility.RegistryAuthLocator - Looking up auth config for image: testcontainers/ryuk:0.3.3 at registry: https://index.docker.io/v1/
21:17:47.532 [main] DEBUG org.testcontainers.utility.RegistryAuthLocator - RegistryAuthLocator has configFile: /qwe/user/.docker/config.json (does not exist) and commandPathPrefix:
21:17:47.532 [main] INFO org.testcontainers.utility.RegistryAuthLocator - Failure when attempting to lookup auth config. Please ignore if you don't have images in an authenticated registry. Details: (dockerImageName: testcontainers/ryuk:0.3.3, configFile: /qwe/user/.docker/config.json. Falling back to docker-java default behaviour. Exception message: /qwe/user/.docker/config.json (No such file or directory)
21:17:47.534 [main] DEBUG org.testcontainers.utility.RegistryAuthLocator - No matching Auth Configs - falling back to defaultAuthConfig [null]
21:17:47.534 [main] DEBUG org.testcontainers.dockerclient.AuthDelegatingDockerClientConfig - Effective auth config [null]
echo "bad" > ~/.docker/config.json
// lauch some test containers tests will now fail <-- this is no longer true

21:23:04.943 [main] INFO 🐳 [testcontainers/ryuk:0.3.3] - Creating container for image: testcontainers/ryuk:0.3.3
21:23:04.946 [main] DEBUG org.testcontainers.dockerclient.AuthDelegatingDockerClientConfig - Delegate call to effectiveAuthConfig failed with cause: 'Failed to parse docker configuration file'. Resolution of auth config will continue using RegistryAuthLocator.
21:23:04.947 [main] DEBUG org.testcontainers.utility.RegistryAuthLocator - Looking up auth config for image: testcontainers/ryuk:0.3.3 at registry: https://index.docker.io/v1/
21:23:04.948 [main] DEBUG org.testcontainers.utility.RegistryAuthLocator - RegistryAuthLocator has configFile: /qwe/user/.docker/config.json (exists) and commandPathPrefix:
21:23:04.949 [main] INFO org.testcontainers.utility.RegistryAuthLocator - Failure when attempting to lookup auth config. Please ignore if you don't have images in an authenticated registry. Details: (dockerImageName: testcontainers/ryuk:0.3.3, configFile: /qwe/user/.docker/config.json. Falling back to docker-java default behaviour. Exception message: Unrecognized token 'bad': was expecting ('true', 'false' or 'null')
 at [Source: /qwe/user/.docker/config.json; line: 1, column: 5]
21:23:04.950 [main] DEBUG org.testcontainers.utility.RegistryAuthLocator - No matching Auth Configs - falling back to defaultAuthConfig [AuthConfig{username=null, password=blank, auth=blank, email=null, registryAddress=https://index.docker.io/v1/, registryToken=blank}]
21:23:04.950 [main] DEBUG org.testcontainers.dockerclient.AuthDelegatingDockerClientConfig - Effective auth config [AuthConfig{username=null, password=blank, auth=blank, email=null, registryAddress=https://index.docker.io/v1/, registryToken=blank}]
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix docker error loading config file - Bobcares
The docker error loading config file triggers due to reasons like an empty config file or permission issue with the configuration file.
Read more >
Docker Compose release notes
Fixed invalid handler warning on Windows builds. Fixed config hash to trigger container re-creation on IPC mode updates. Fixed conversion map for placement....
Read more >
How to Deploy an NGINX Image with Docker
Option 1 – Maintain the Content and Configuration on the Docker Host ... Now any change made to the files in the local...
Read more >
fabric8io/docker-maven-plugin
See Simple Dockerfile build for details of this zero XML configuration mode. Images that are built with this plugin can be pushed to...
Read more >
OpenShift CLI developer command reference
Check to see if I can create pods in any namespace oc auth can-i create pods ... pod.json | oc create -f -...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found