Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Docker Config File Package
Problem: Need a better config file manager for Docker
There are several issues this PR is trying to address
1 - the current Docker CLI config file is really just used as a store for registry authentication data.
This makes it hard to use for other config options, like storing the value of DOCKER_HOST.
2 - 3rd party tooling, that might wish to modify any config values we store in a config file, would
have to write their own config file parser/editor - which is error prone
3 - end users who wish to modify any config file properties would either need to creat their own tooling,
or bring up the config file in an editor and hack at it, again all error prone.
This PR does several things:
1 - introduces a new pkg called "config" which does:
* loading/saving of a config struct to a json file
* supports modifications of the config struct via normal updates to its properties: config.A = 5
* supports modifications to the config struct via dynamic funcs: config.Set("A", "5")
2 - introduces a new CLI config file called ".dockercli"
3 - adds a new docker command: docker config
which allows for people to manipulate the .dockercli config file via the command line. E.g.:
docker config dump # to see the current json
docker config list # to list all properties in config file
docker config get DockerHost # show value of "DockerHost" property
docker config set DockerHost # set "DockerHost" to ""
4 - introduces a "DockerHost" property in the config file. Order of precedence is:
-H on the cmd line, overrides DOCKER_HOST env var, which overrides "DockerHost" config property
5 - introduces a "--config file" option so that the user can point to a specific config file. This will
be usefule when more than one docker cli is running at the same time, on the same host, and they need
to have different config properties (like auth tokens).
6 - Adds an HttpHeaders property to config file that specifies additional http headrs to include on
outgoing HTTP messages from cli to daemon. Adding auth headers/token is the primary usecase for this.
The hope is that with this infrastructure we can then we reused by the other Docker projects (machine, swarm, ...).
Design Factors:
As this PR was being developed the following factors helped shape its design:
* Wanted an easy to edit/read config file - picked json
* Wanted an easy API for Docker devs to use. Once the config file is converted into a Go struct, it made sense
allow peopel to continue to use what they do today - just access properties via their Go names. For example:
* Wanted a dynamic API as well so that we could make 3rd party tooling easy. For example, while they could
import our files and access the struct directly, a command line interface would be even easier at times.
For example: docker config get
But in order to support this kind of dynamic referencing we needed to be able to convert
"" back-n-forth between config.Foo["bar"]. To enable this there's are generic Get/Set
operations on the config entity so you can do: config.Get("") and config.Set("", "hi")
Note, that this came config entity also supports config.Foo["bar"] so people can choose which one they
want to use.
Next steps if the basic idea is accepted:
- Migrate .dockercfg data into .dockercli so we just have one config file
- Make other options available (like the othe env vars - e.g. DOCKER_TLS_VERIFY )
Sample .dockercli file:
"DockerHost": "",
"HttpHeaders": {
"Test1": "FOO",
"Test2": "222FOO"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment