Signing back into the Community for the first time? You'll need to reset your password to access your account.  Find out more.

Forum Discussion

Former Member's avatar
Former Member
2 years ago

Secrets as environment variables in docker-compose files

I always want to make everything easier, and since I did see 1password supported secrets, I was wondering if its possible to use this with docker-compose (not hosting it, but using it as environment variables in composer files?).

It seems like its only Kubernites / K8 integration, but maybe someone have come up with a different way to do it?


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided
Browser:_ Not Provided

  • Former Member's avatar
    Former Member

    Hi @alekslyse, thanks for reaching out and for your interest in using secrets with 1Password!

    Based on your question there are a couple of options that could work for you; both involve the 1Password CLI (docs: https://developer.1password.com/docs/cli/).

    op inject

    ```sh

    use the ref.env file (containing secret references) as input, and output the resolved secrets to the .env file

    op inject -i ref.env -o .env

    pass the .env file with resolved secrets to docker-compose

    docker-compose —env-file .env up -d

    remove the .env file from the disk

    rm .env
    ```

    op run

    ```sh

    note that the resolved secrets need to be specified by variable name when passing them to docker-compose as env vars

    op run —env-file .env — docker-compose run -e SECRET1=$SECRET1 -e SECRET2=$SECRET2 web python console.py
    ```

    I hope that these suggestions help! Please let us know if you run into any issues.

    -- Dustin