Learn how to use Infisical to inject environment variables into a Docker container.
This approach allows you to inject secrets from Infisical directly into your application.
This is achieved by installing the Infisical CLI into your docker image and modifying your start command to execute with Infisical.
Starting your service with the Infisical CLI pulls your secrets from Infisical and injects them into your service.
Copy
Ask AI
CMD ["infisical", "run", "--", "[your service start command]"]# example with single single commandCMD ["infisical", "run", "--", "npm", "run", "start"]# example with multiple commandsCMD ["infisical", "run", "--command", "npm run start && ..."]
Head to your project settings in the Infisical dashboard to generate an service token.
This service token will allow you to authenticate and fetch secrets from Infisical.
Once you have created a service token with the required permissions, you’ll need to feed the token to the CLI installed in your docker container.
The last step is to give the Infisical CLI installed in your Docker container access to the service token. This will allow the CLI to fetch and inject the secrets into your application.To feed the service token to the container, use the INFISICAL_TOKEN environment variable as shown below.
Copy
Ask AI
docker run --env INFISICAL_TOKEN=[token] [DOCKER-IMAGE]...