testcontainers / testcontainers-rs

A library for integration-testing against docker containers from within Rust.
https://rust.testcontainers.org
Apache License 2.0
745 stars 142 forks source link

example usage for DOCKER_AUTH_CONFIG #728

Closed amab8901 closed 1 month ago

amab8901 commented 1 month ago

Hi!

I read in the docs about DOCKER_AUTH_CONFIG being used for authenticating via Docker. Can u give me examples of how this is used?

DDtKey commented 1 month ago

Hi @amab8901 👋

It's generally documented on our docs site and docs.rs too

DOCKER_AUTH_CONFIG allows to set a json content (just like raw content of config.json), while DOCKER_CONFIG allows to set path to your custom config file.

Content is like:

{
    "auths": { },
    "credsStore": "..."
}
amab8901 commented 1 month ago

I haven't used docker config files before. If my username is user123 and my password is pass123, should I write the following as a value to DOCKER_AUTH_CONFIG?

{
  "auths": { 
    "username": "user123",
    "password": "pass123"
  },
  "credsStore": ""
}
DDtKey commented 1 month ago

Not really, "auths" represents list of registries and their configs.

You can check the one managed by docker (via docker login command). And testcontainers uses this one by default.

cat ~/.docker/config.json
amab8901 commented 1 month ago

I don't have username and password stored in docker config, so doing cat ~/.docker/config.json doesn't reveal to me where I'm supposed to put the username and password in the docker config

DDtKey commented 1 month ago

Usually Credential Store is used and username and passwords are not part of config itself, see https://docs.docker.com/reference/cli/docker/login/