Reputation: 3351
Is there a way to dump the environment variables in the docker-compose.yml into a file on a given container?
Example:
version: "3"
services:
api:
image: registry.gitlab.com/my-api
environment:
- TOKEN=123
- DB_NAME=db
I would like to create a .env file automatically inside the api
container after the docker-compose run -d
command.
Upvotes: 0
Views: 666
Reputation: 5086
Something like this?
version: "3"
services:
test:
image: alpine
environment:
API_URL: "test"
TEST: "test"
volumes:
- envstorage:/env
command: "cat /env/storeme"
depends_on:
- variable-storer
variable-storer:
image: alpine
environment:
TEST_1: "test"
TEST_2: "test"
TEST_3: "test"
TEST_4: "test"
TEST_5: "test"
TEST_6: "test"
volumes:
- envstorage:/env
command: "sh -c 'env > /env/storeme'"
volumes:
envstorage:
name: 'env-test'
NOTE: this is as hacky as it can be.
Upvotes: 1