๐Ÿ“˜

These steps are for integrating a Docker-based environment with the envkey-source integration tool. If you instead integrate with a language-specific wrapper, you won't need to do anything else to integrate with Docker.

Generate and set an ENVKEY

Generate an ENVKEY and make it available to your container as an environment variable.

  • For a server environment where your platform runs the Docker container for you, either set an environment variable for your ENVKEY at the platform level, and make sure it's exposed to your container when it's run, or even better, if your platform offers secrets management, create a secret for your ENVKEY then expose the secret as an environment variable to your container.

  • For a local development environment or a server environment where you execute docker run yourself, you can pass the ENVKEY to docker run to make it available:

  $ docker run -e "ENVKEY=$ENVKEY" .

You can also use a .env file and pass that to docker run. For example, when you generate a local development ENVKEY in the EnvKey UI, you'll see something like this:

Depending on where you put your ENVKEY in a file, you can pass it to docker run like this:

  $ docker run --env-file $HOME/.envkey/apps/285e21a7-93c4-48c5-9c14-e23454e4f7a5.env

Yet another option is to mount the .env file into your container at either one of the locations shown in the
screenshot above.

โ—๏ธ

Don't check it in!

However you make your ENVKEY available, make sure you don't check it into version control.

Update your Dockerfile

In your Dockerfile, install envkey-source and use it to execute process(es) with your EnvKey config:

FROM node:16-alpine

WORKDIR /usr/src/app

# Install envkey-source:
#
# --> Install required dependencies (adapt to your distro)
RUN apk --no-cache add curl bash
#
# --> For an Ubuntu-based image:
# RUN apt-get update && apt-get -y curl
#
# --> Install latest version (replace VERSION=... below to pin a version)
RUN VERSION=$(curl https://envkey-releases.s3.amazonaws.com/latest/envkeysource-version.txt) \ 
  && curl -s https://envkey-releases.s3.amazonaws.com/envkeysource/release_artifacts/$VERSION/install.sh | bash

# Install app dependencies
COPY package*.json ./
RUN npm ci --only=production

# Copy files
COPY server.js server.js

# Expose port
EXPOSE 8081

# Start app with the latest environment, with automatic rolling reloads enabled 
CMD envkey-source -w --rolling -- node server.js

# Use the `es` command to type a bit less
# CMD es -w --rolling -- node server.js

# To instead run a custom command on reload, use the -r flag.
# CMD es -r ./reloaded-env.sh --rolling -- node server.js

# You can also use the -w and -r flags together to auto-restart *and* run a custom command:
# CMD es -w -r ./reloaded-env.sh --rolling -- node server.js

# Or to restart manually after an update, just:
# CMD es -- node server.js