Prerequisites
- An Infisical account on Infisical Cloud or a self-hosted instance
- A project with secrets configured
- Docker installed
- The Infisical CLI installed on the machine where you run Docker
- An application or container image to run
Setup
Choose how Docker should receive your application secrets:- Fetch at startup (Recommended)
- Docker Run (Interactive)
- Docker Run (CI/CD)
This method installs the Infisical CLI in your image and uses it to start your application. The CLI fetches secrets when the container starts and injects them into the application process.Infisical creates the identity with Universal Auth enabled and opens its details page.Next, wrap your application’s start command with
On the machine where Docker runs, authenticate the machine identity and start the container using the commands for your Infisical deployment:Replace
We strongly recommend this method, since it works for both local development and automated/production environments.
Step 1: Create a machine identity
Create a machine identity for your application:1
In your project, select Project Settings > Access Control > Machine Identities.
2
Select Add Machine Identity, then select Create New.
3
Enter a name (e.g.,
orders-service-docker), select a role that can read secrets, and select Create.Step 2: Create a client secret
Create credentials that the application can exchange for a short-lived access token:1
In the machine identity’s Authentication section, select Universal Auth.
2
Copy the Client ID and save it somewhere secure for the next step.
3
Select Create Client Secret, enter a description (e.g.,
docker-quickstart), and select Create.4
Copy the Client Secret. You won’t be able to view it again.
Machine identity access tokens are short-lived. Token expiration doesn’t affect an application after
infisical run has fetched its secrets, but the container needs a valid token every time it starts.In automated deployments, store the Client ID and Client Secret in your deployment platform’s secret store and run infisical login immediately before each docker run or docker compose up.Step 3: Copy your project ID
In your project, select Project Settings, then select Copy Project ID. You’ll add this ID to your Dockerfile in the next step.Step 4: Update your Dockerfile
Add the Infisical CLI installation that matches your base image:infisical run. Replace <project-id> with the project ID you copied earlier:Run multiple startup commands
Run multiple startup commands
Use the
--command option when your application needs to run multiple shell commands in sequence:Step 5: Build and run your container
Build your image:If your self-hosted Infisical instance is running locally on the Docker host, don’t set
INFISICAL_DOMAIN to a localhost URL, since this will point to the container itself.Instead, set it to a host.docker.internal URL, which points to the container’s host domain.<client-id> and <client-secret> with the machine identity credentials you created earlier. The access token is passed to the container at runtime and isn’t stored in the image.Your application can now read secrets as environment variables when the container starts.
Use with Docker Compose
If you fetch secrets at startup, you can use Docker Compose to build and run one or more configured service images. Configure each image to start throughinfisical run, then configure your Compose file for your Infisical deployment:
If your self-hosted Infisical instance is running locally on the Docker host, don’t set
INFISICAL_DOMAIN to a localhost URL, since this will point to the container itself.Instead, set it to a host.docker.internal URL, which points to the container’s host domain.