amit
amit

Reputation: 2331

What are the benefits of docker config over setting environment variables for containers?

Both Docker config and setting environment variables for containers seems to accomplish the same goals. Especially when considering the environment variables to set can get fetched from a file (env_file).

What are the benefits of docker config over setting environment variables for containers?

Upvotes: 4

Views: 1463

Answers (1)

Pierre B.
Pierre B.

Reputation: 12933

There are many, but it's mainly a matter of choice. Here are some benefits:

  • Docker config are immutable, where environment variable are not (this one may be both a benefit and drawback though)
  • Docker config are easily manageable with docker config commands where environment variables are not
  • Environment variables may collide in your container: you may use environment variable MONGODB_HOST=mongodb://foo:bar@my-mongo:27017 pointing to Mongo database but a library you are using in your application will also use this variable but expect a simple hostname such as my-mongo and throw an exception at runtime
  • Config file may have restricted read permission (i.e. only the applicative user may read it), where environment variable may leak to a sub-process or anyone accessing your container
  • Config file may be splitted in several parts for readability or management in your container, environment variables cannot
  • When checking what are your effective container configuration (i.e. running a shell in your container and looking around), using config file is much easier than showing a bunch of potentially unrelated environment variables (cat myconfig VS. env)
  • In summary, config file are more partitioned and manageable than environment variables

You may take a look at this post which is not Docker specific but may give some insights.

Upvotes: 6

Related Questions