Currently I am using docker-compose file to setup my dev/prod environments. I am using environment variables to store secrets, database credentials etc. After some search, I found out that Vault can be used to secure the credentials. I tried couple of basic examples with vault, but still I have no idea of how to use Vault with a docker-compose file. Can someone point me to a correct way. If Vault is not a good solution with docker-compose, what are the mechanisms I could use to secure credentials rather than storing them in environment as plain text.
The Compose file provides a way to document and configure all of the application's service dependencies (databases, queues, caches, web service APIs, etc). Using the Compose command line tool you can create and start one or more containers for each dependency with a single command ( docker-compose up ).
Running the Vault container with no arguments will give you a Vault server in development mode. The provided entry point script will also look for Vault subcommands and run vault with that subcommand. For example, you can execute docker run vault status and it will run the vault status command inside the container.
Docker compose uses the Dockerfile if you add the build command to your project's docker-compose. yml. Your Docker workflow should be to build a suitable Dockerfile for each image you wish to create, then use compose to assemble the images using the build command.
This is my current docker-compose config for using Vault in dev, but I use dedicated servers (not Docker) in production.
# docker_compose.yml version: '2' services: myvault: image: vault container_name: myvault ports: - "127.0.0.1:8200:8200" volumes: - ./file:/vault/file:rw - ./config:/vault/config:rw cap_add: - IPC_LOCK entrypoint: vault server -config=/vault/config/vault.json
The volume mounts ensure the vault config is saved if you have to rebuild the container.
To use the 'file' backend, to make this setup portable for Docker/Git, you will also need to create a directory called config
and put this file into it, named vault.json
:
# config/vault.json { "backend": {"file": {"path": "/vault/file"}}, "listener": {"tcp": {"address": "0.0.0.0:8200", "tls_disable": 1}}, "default_lease_ttl": "168h", "max_lease_ttl": "0h" }
Notes:
Although the ROOT_TOKEN
is static in this configuration (will not change between container builds), any generated VAULT_TOKEN
issued for an app_role
will be invalidated every time the vault has to be unsealed.
I have found the Vault sometimes becomes sealed when the container is restarted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With