Skip to content

Commit b5a11c6

Browse files
committed
docs: expand README with config sharing, MCP notes, and more examples
- Add detailed usage examples (full-auto, quiet mode) - Document ~/.codex folder structure and custom instructions - Add MCP support section with limitations and workarounds - Clarify OAuth two-step login process with port exposure - Update docker-compose to mount ~/.codex from host - Add shell alias convenience section - Add Docker-in-Docker sandbox mode docs
1 parent be649bd commit b5a11c6

2 files changed

Lines changed: 237 additions & 46 deletions

File tree

README.md

Lines changed: 209 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,57 @@ docker run -it --rm \
1717
- [Docker](https://docs.docker.com/get-docker/) installed
1818
- [OpenAI API key](https://platform.openai.com/api-keys) or ChatGPT account for OAuth
1919

20-
## Usage
20+
## Usage Examples
2121

22-
### Using Docker Run
22+
### Basic Interactive Session
2323

2424
```bash
25-
# Basic usage with API key
25+
# Start an interactive Codex session
2626
docker run -it --rm \
2727
-v $(pwd):/workspace \
2828
-e OPENAI_API_KEY=$OPENAI_API_KEY \
2929
ungb/codex
30+
```
31+
32+
### One-Shot Commands
3033

31-
# With persistent config (remembers settings between runs)
34+
```bash
35+
# Ask a question about your codebase
3236
docker run -it --rm \
3337
-v $(pwd):/workspace \
34-
-v codex-config:/home/coder/.codex \
3538
-e OPENAI_API_KEY=$OPENAI_API_KEY \
36-
ungb/codex
39+
ungb/codex \
40+
codex "explain the architecture of this project"
41+
42+
# Generate code
43+
docker run -it --rm \
44+
-v $(pwd):/workspace \
45+
-e OPENAI_API_KEY=$OPENAI_API_KEY \
46+
ungb/codex \
47+
codex "add input validation to the user form"
48+
49+
# Fix bugs
50+
docker run -it --rm \
51+
-v $(pwd):/workspace \
52+
-e OPENAI_API_KEY=$OPENAI_API_KEY \
53+
ungb/codex \
54+
codex "fix the type errors in src/utils"
3755

38-
# With git/ssh support
56+
# Refactor code
3957
docker run -it --rm \
4058
-v $(pwd):/workspace \
41-
-v codex-config:/home/coder/.codex \
59+
-e OPENAI_API_KEY=$OPENAI_API_KEY \
60+
ungb/codex \
61+
codex "refactor this function to use async/await"
62+
```
63+
64+
### With Full Configuration (Recommended)
65+
66+
```bash
67+
# Full setup with persistent config, git, and SSH
68+
docker run -it --rm \
69+
-v $(pwd):/workspace \
70+
-v ~/.codex:/home/coder/.codex \
4271
-v ~/.ssh:/home/coder/.ssh:ro \
4372
-v ~/.gitconfig:/home/coder/.gitconfig:ro \
4473
-e OPENAI_API_KEY=$OPENAI_API_KEY \
@@ -47,13 +76,13 @@ docker run -it --rm \
4776

4877
### Using Docker Compose
4978

50-
1. Clone this repo or copy `docker-compose.yml` to your project:
79+
1. Copy `docker-compose.yml` to your project:
5180

5281
```bash
5382
curl -O https://raw.githubusercontent.com/ungb/codex-docker/main/docker-compose.yml
5483
```
5584

56-
2. Create a `.env` file with your API key:
85+
2. Create a `.env` file:
5786

5887
```bash
5988
echo "OPENAI_API_KEY=your-key-here" > .env
@@ -62,80 +91,192 @@ echo "OPENAI_API_KEY=your-key-here" > .env
6291
3. Run:
6392

6493
```bash
94+
# Interactive session
6595
docker compose run --rm codex
96+
97+
# One-shot command
98+
docker compose run --rm codex codex "explain this code"
6699
```
67100

68-
### Run a Specific Command
101+
### Full Auto Mode (Careful!)
69102

70103
```bash
71-
# Run codex with arguments
104+
# Auto-approve all changes (use with caution)
72105
docker run -it --rm \
73106
-v $(pwd):/workspace \
74107
-e OPENAI_API_KEY=$OPENAI_API_KEY \
75108
ungb/codex \
76-
codex "explain this codebase"
109+
codex --full-auto "implement the TODO items in this file"
110+
```
77111

78-
# Check version
79-
docker run -it --rm ungb/codex codex --version
112+
### Quiet Mode
80113

81-
# Run with full auto-approve (be careful!)
114+
```bash
115+
# Less verbose output
82116
docker run -it --rm \
83117
-v $(pwd):/workspace \
84118
-e OPENAI_API_KEY=$OPENAI_API_KEY \
85119
ungb/codex \
86-
codex --full-auto "fix the tests"
120+
codex --quiet "fix the failing tests"
87121
```
88122

123+
## Sharing Your Codex Configuration
124+
125+
The `~/.codex` directory contains your Codex configuration and session history.
126+
127+
### What's in ~/.codex
128+
129+
```
130+
~/.codex/
131+
├── config.json # Settings and preferences
132+
├── instructions.md # Custom instructions for Codex
133+
└── history/ # Session history
134+
```
135+
136+
### Mount Your Configuration
137+
138+
```bash
139+
# Share your Codex config folder
140+
docker run -it --rm \
141+
-v $(pwd):/workspace \
142+
-v ~/.codex:/home/coder/.codex \
143+
-e OPENAI_API_KEY=$OPENAI_API_KEY \
144+
ungb/codex
145+
```
146+
147+
### Custom Instructions
148+
149+
Create `~/.codex/instructions.md` with custom instructions that Codex will follow:
150+
151+
```markdown
152+
# My Codex Instructions
153+
154+
- Always use TypeScript strict mode
155+
- Prefer functional programming patterns
156+
- Add JSDoc comments to public functions
157+
```
158+
159+
Then mount it:
160+
161+
```bash
162+
docker run -it --rm \
163+
-v $(pwd):/workspace \
164+
-v ~/.codex:/home/coder/.codex \
165+
-e OPENAI_API_KEY=$OPENAI_API_KEY \
166+
ungb/codex
167+
```
168+
169+
## MCP (Model Context Protocol) Support
170+
171+
> **Warning**: MCP support in Docker containers is limited and may require additional configuration.
172+
173+
### Current Limitations
174+
175+
MCP servers may not work out of the box in Docker because:
176+
177+
1. **Stdio-based MCP servers** need the server binary installed inside the container
178+
2. **Network-based MCP servers** need proper network configuration
179+
3. **MCP servers that access local resources** need those resources mounted
180+
4. **Authentication** for MCP servers may not transfer into the container
181+
182+
### What Might Work
183+
184+
| MCP Type | Status | Notes |
185+
|----------|--------|-------|
186+
| HTTP/SSE servers (remote) | May work | Requires `--network host` or port mapping |
187+
| Stdio servers (local) | Unlikely | Server must be installed in container |
188+
| Servers needing local files | Partial | Files must be mounted |
189+
| Servers with OAuth | Unlikely | Auth flow may not complete |
190+
191+
### Attempting MCP with Docker
192+
193+
```bash
194+
# Mount MCP config and use host network
195+
docker run -it --rm \
196+
--network host \
197+
-v $(pwd):/workspace \
198+
-v ~/.codex:/home/coder/.codex \
199+
-e OPENAI_API_KEY=$OPENAI_API_KEY \
200+
ungb/codex
201+
```
202+
203+
### Building a Custom Image with MCP Servers
204+
205+
```dockerfile
206+
FROM ungb/codex:latest
207+
208+
USER root
209+
RUN npm install -g @modelcontextprotocol/some-server
210+
USER coder
211+
```
212+
213+
### MCP Investigation Needed
214+
215+
Full MCP support requires further investigation. If you have solutions, please open an issue or PR!
216+
89217
## Authentication
90218

91219
### Option 1: API Key (Recommended for Docker)
92220

93-
Get an API key from [OpenAI Platform](https://platform.openai.com/api-keys) and pass it as an environment variable:
221+
Get an API key from [OpenAI Platform](https://platform.openai.com/api-keys):
94222

95223
```bash
96224
-e OPENAI_API_KEY=sk-...
97225
```
98226

99227
### Option 2: ChatGPT OAuth Login
100228

101-
For browser-based OAuth, expose port 1455 for the callback:
229+
OAuth login is a two-step process:
230+
231+
**Step 1: Login (once)**
102232

103233
```bash
234+
# Login with browser OAuth - expose port 1455 for callback
104235
docker run -it --rm \
105236
-p 1455:1455 \
106-
-v $(pwd):/workspace \
107-
-v codex-config:/home/coder/.codex \
237+
-v ~/.codex:/home/coder/.codex \
108238
ungb/codex \
109239
codex login
110240
```
111241

112-
Or use host network mode:
242+
Or use host network:
113243

114244
```bash
115245
docker run -it --rm \
116246
--network host \
117-
-v $(pwd):/workspace \
118-
-v codex-config:/home/coder/.codex \
247+
-v ~/.codex:/home/coder/.codex \
119248
ungb/codex \
120249
codex login
121250
```
122251

252+
**Step 2: Use normally**
253+
254+
```bash
255+
# Now run without API key - tokens are in ~/.codex
256+
docker run -it --rm \
257+
-v $(pwd):/workspace \
258+
-v ~/.codex:/home/coder/.codex \
259+
ungb/codex
260+
```
261+
262+
> **Note**: Mount `~/.codex` from your host so tokens persist between container runs.
263+
123264
## Volume Mounts
124265

125266
| Mount | Purpose |
126267
|-------|---------|
127268
| `/workspace` | Your project directory (required) |
128-
| `/home/coder/.codex` | Codex config and cache (optional, for persistence) |
129-
| `/home/coder/.ssh` | SSH keys for git operations (optional, read-only) |
130-
| `/home/coder/.gitconfig` | Git configuration (optional, read-only) |
269+
| `/home/coder/.codex` | Codex config, instructions, history |
270+
| `/home/coder/.ssh` | SSH keys for git operations (read-only) |
271+
| `/home/coder/.gitconfig` | Git configuration (read-only) |
131272

132273
## Environment Variables
133274

134275
| Variable | Required | Description |
135276
|----------|----------|-------------|
136277
| `OPENAI_API_KEY` | Yes* | Your OpenAI API key |
137278
| `OPENAI_ORG_ID` | No | OpenAI organization ID |
138-
| `OPENAI_API_BASE` | No | Custom API endpoint (for proxies) |
279+
| `OPENAI_API_BASE` | No | Custom API endpoint |
139280

140281
*Required unless using OAuth login
141282

@@ -145,6 +286,36 @@ docker run -it --rm \
145286
|------|---------|
146287
| 1455 | OAuth callback for `codex login` |
147288

289+
## Utility Commands
290+
291+
```bash
292+
# Check version
293+
docker run --rm ungb/codex codex --version
294+
295+
# Show help
296+
docker run --rm ungb/codex codex --help
297+
298+
# View configuration
299+
docker run --rm \
300+
-v ~/.codex:/home/coder/.codex \
301+
ungb/codex \
302+
cat /home/coder/.codex/config.json
303+
```
304+
305+
## Sandbox Mode
306+
307+
Codex recommends Docker for sandboxing. When you run Codex inside this container, it's already isolated from your host system.
308+
309+
For nested Docker (Docker-in-Docker), mount the Docker socket:
310+
311+
```bash
312+
docker run -it --rm \
313+
-v $(pwd):/workspace \
314+
-v /var/run/docker.sock:/var/run/docker.sock \
315+
-e OPENAI_API_KEY=$OPENAI_API_KEY \
316+
ungb/codex
317+
```
318+
148319
## Building Locally
149320

150321
```bash
@@ -157,8 +328,6 @@ docker build -t codex .
157328

158329
### Permission Denied on Mounted Files
159330

160-
The container runs as user `coder` (UID 1000). If you have permission issues:
161-
162331
```bash
163332
# Run with your user ID
164333
docker run -it --rm \
@@ -170,8 +339,6 @@ docker run -it --rm \
170339

171340
### Git Operations Failing
172341

173-
Ensure SSH keys are mounted and git is configured:
174-
175342
```bash
176343
docker run -it --rm \
177344
-v $(pwd):/workspace \
@@ -188,22 +355,25 @@ Ensure port 1455 is exposed:
188355
```bash
189356
docker run -it --rm \
190357
-p 1455:1455 \
191-
-v $(pwd):/workspace \
192-
-v codex-config:/home/coder/.codex \
358+
-v ~/.codex:/home/coder/.codex \
193359
ungb/codex \
194360
codex login
195361
```
196362

197-
## Sandbox Mode
363+
## Shell Alias (Convenience)
198364

199-
Codex supports running in sandbox mode using Docker. When you run Codex inside this container, it's already isolated. For nested Docker support (Docker-in-Docker), mount the Docker socket:
365+
Add to your `~/.bashrc` or `~/.zshrc`:
200366

201367
```bash
202-
docker run -it --rm \
368+
alias codex-docker='docker run -it --rm \
203369
-v $(pwd):/workspace \
204-
-v /var/run/docker.sock:/var/run/docker.sock \
370+
-v ~/.codex:/home/coder/.codex \
371+
-v ~/.ssh:/home/coder/.ssh:ro \
372+
-v ~/.gitconfig:/home/coder/.gitconfig:ro \
205373
-e OPENAI_API_KEY=$OPENAI_API_KEY \
206-
ungb/codex
374+
ungb/codex codex'
375+
376+
# Usage: codex-docker "explain this code"
207377
```
208378

209379
## License

0 commit comments

Comments
 (0)