| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A containerized environment for running the OpenAI Codex CLI. This image provides a rootless, minimal setup so you can run codex commands with local file access and API key–based authentication.
Build from the provided Dockerfile:
docker build -t codex-cli:dev .Customize via build args if needed:
docker build \
--build-arg CODEX_CLI_VERSION=latest \
--build-arg USERNAME=codex \
--build-arg UID=1000 \
--build-arg GID=1000 \
-t codex-cli:dev .The Codex CLI authenticates with OpenAI using an API key. Pass your key as an environment variable when running the container.
Avoid placing secrets directly on the command line (they can leak via shell history and process inspection). Use an ephemeral prompt and pass the variable through:
# Prompts without echoing; does not store secret in history
read -s OPENAI_API_KEY && \
docker run -it \
-v ${PWD}:/work \
-e OPENAI_API_KEY \
--rm codex-cli:dev --help; \
unset OPENAI_API_KEY# Create a protected env file (avoid echoing secrets in your history)
install -m 600 /dev/null .env
# Edit securely with your editor to add keys
${EDITOR:-vi} .env
# Example contents to add (edit in the editor):
# OPENAI_API_KEY=...
# OPENAI_ORG_ID=org_...
# OPENAI_PROJECT=proj_...
# OPENAI_BASE_URL=https://api.openai.com/v1
# Use the environment file with Docker
docker run -it -v ${PWD}:/work --env-file .env --rm codex-cli:dev --helpSecurity tips for env files:
Run a simple command and confirm it executes without auth errors:
docker run -it -v ${PWD}:/work --env-file .env --rm codex-cli:dev --versionUse this if your OpenAI models are deployed on Azure OpenAI. You will need:
There are two supported ways to configure Codex for Azure: via environment variables or via a config file at ~/.codex/config.toml (as described in Microsoft’s guide).
Set these to point Codex at your Azure OpenAI endpoint:
When targeting a specific deployment, pass it as the model name (the deployment name), for example with --model <your-deployment-name> when invoking Codex commands.
Example .env for Azure:
AZURE_OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
OPENAI_BASE_URL=https://<your-resource>.openai.azure.com/openai
OPENAI_API_VERSION=2024-05-01-previewCodex also supports a TOML config file in your home directory. This is useful to persist Azure settings and deployment names without repeating flags. Create ~/.codex/config.toml on your host with content like:
# ~/.codex/config.toml
[default]
provider = "azure-openai"
[providers.azure-openai]
# Your Azure OpenAI resource endpoint (no trailing /openai path needed here)
endpoint = "https://<your-resource>.openai.azure.com"
api_version = "2024-05-01-preview"
# Deployment names you created in the Azure OpenAI resource
chat_deployment = "<your-chat-deployment>"
embedding_deployment = "<your-embeddings-deployment>"
# Use this environment variable for the API key
api_key_env = "AZURE_OPENAI_API_KEY"Notes:
Using environment variables only (without exposing secrets on the command line):
# Prompt for the Azure key without echoing
read -s AZURE_OPENAI_API_KEY && \
docker run -it --rm \
-v ${PWD}:/work \
-e AZURE_OPENAI_API_KEY \
-e OPENAI_BASE_URL="https://<your-resource>.openai.azure.com/openai" \
-e OPENAI_API_VERSION="2024-05-01-preview" \
codex-cli:dev --help; \
unset AZURE_OPENAI_API_KEYUsing ~/.codex/config.toml plus an .env file that only carries the key:
# Ensure ~/.codex/config.toml exists on host; .env carries only the key
# Create protected .env (once):
install -m 600 /dev/null .env
${EDITOR:-vi} .env
# In .env, add only:
# AZURE_OPENAI_API_KEY=...
docker run -it --rm \
-v $HOME:/home/codex \
-v ${PWD}:/work \
--env-file .env \
codex-cli:dev --helpUse a working directory mount so Codex can read/write files in your project.
docker run -it -v ${PWD}:/work --env-file .env --rm codex-cli:dev [CODEX_ARGS]Replace [CODEX_ARGS] with the arguments supported by your installed @openai/codex version (see --help).
The image sets /work as the working directory. This means:
Start an interactive session to run multiple Codex commands:
docker run -it -v ${PWD}:/work --env-file .env --rm codex-cli:devRun a single command, for example to see help or version information:
# Help
docker run -it -v ${PWD}:/work --env-file .env --rm codex-cli:dev --help
# Version
docker run -it -v ${PWD}:/work --env-file .env --rm codex-cli:dev --versionCreate a shell alias for shorter commands:
# Add to your ~/.bashrc or ~/.zshrc
alias codex='docker run -it -v ${PWD}:/work --env-file .env --rm codex-cli:dev'
# Then simply use:
codex --helpThe container runs as user codex with UID 1000. If your host user has a different UID/GID, you may encounter permission issues. To resolve this:
docker build \
--build-arg UID=$(id -u) \
--build-arg GID=$(id -g) \
-t codex-cli:dev .# If files are created with unexpected ownership
sudo chown -R $(id -u):$(id -g) ./path-to-files| Back | FazBrowse Home | New Git URL |