Skip to content

Instantly share code, notes, and snippets.

@mlin
Last active May 3, 2025 18:38
Show Gist options
  • Select an option

  • Save mlin/a94f3e5bfc88f5372394d7304bf192dc to your computer and use it in GitHub Desktop.

Select an option

Save mlin/a94f3e5bfc88f5372394d7304bf192dc to your computer and use it in GitHub Desktop.
codex-docker
This file only exists to set the gist title.
  1. Clone this gist
  2. In the cloned directory, add creds.sh containing: export OPENAI_API_KEY=...
  3. Edit config.yaml and instructions.md as desired
  4. Change to your project directory and: ~/path/to/gist/codex 'Summarize this project'

To refresh all dependencies: docker build --no-cache -t codex:latest ~/path/to/gist

#!/usr/bin/env bash
set -euo pipefail
# 1) Locate this script’s dir (where your Dockerfile is)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
# 2) Build (or rebuild) the image
docker build --quiet \
-t codex:latest \
"$SCRIPT_DIR"
# 4) ./creds.sh should contain: export OPENAI_API_KEY=...
source "$SCRIPT_DIR"/creds.sh
# 3) Run codex inside Docker, mounting your CWD into /workspace
docker run --rm -it \
-v "$(pwd)":/workspace \
-u $(id -u):$(id -g) \
-e OPENAI_API_KEY \
codex:latest \
"$@"
model: o4-mini # Default model
approvalMode: auto-edit # or suggest, full-auto
fullAutoErrorMode: ask-user # or ignore-and-continue
safeCommands:
- git status
- git branch
- git log
- git diff
- git show
- git rev‑parse
- git tag -l
- git reflog
- git remote -v
FROM node:22-alpine
RUN apk add --no-cache git curl make g++ python3 bash
RUN npm install -g @openai/codex
RUN mkdir -p /home/node/.codex
COPY config.yaml instructions.md /home/node/.codex/
RUN chown -R node:node /home/node/.codex && chmod uga+r /home/node
ENV HOME /home/node
WORKDIR /workspace
RUN chmod 777 /workspace
RUN git config --global --add safe.directory /workspace
RUN git config --global --add safe.directory /workspace/codex
ENTRYPOINT ["codex"]

Since you're running in a container with only a few packages installed, avoid attempts at runtime inspection of package interfaces (e.g. starting an interpreter with a script to dump docstrings). If it's crucial, remind the user to supply specific API docs/stubs before proceeding further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment