Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ COG_BINARY=dist/go/*/cog mise run test:integration

### CLI Architecture (Go)
The CLI follows a command pattern with subcommands. The main components are:
- `pkg/cli/` - Command definitions (build, run, predict, serve, etc.)
- `pkg/cli/` - Command definitions (build, exec, predict, serve, etc.)
- `pkg/docker/` - Docker client and container management
- `pkg/dockerfile/` - Dockerfile generation and templating
- `pkg/config/` - cog.yaml parsing and validation
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ $ curl http://localhost:8080/predictions -X POST \
In development, you can also run arbitrary commands inside the Docker environment:

```console
$ cog run python train.py
$ cog exec python train.py
...
```

Or, [spin up a Jupyter notebook](docs/notebooks.md):

```console
$ cog run -p 8888 jupyter notebook --allow-root --ip=0.0.0.0
$ cog exec -p 8888 jupyter notebook --allow-root --ip=0.0.0.0
```
-->

Expand Down
2 changes: 1 addition & 1 deletion architecture/04-container-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ How coglet gets invoked when running a Cog container:

```mermaid
flowchart TB
cli["cog predict / cog run\n(CLI)"]
cli["cog predict / cog exec\n(CLI)"]

launcher["python -m cog.server.http\nimport coglet\ncoglet.server.serve(predictor_ref, port=5000)"]

Expand Down
12 changes: 6 additions & 6 deletions architecture/06-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The Cog CLI is a Go binary that provides commands for the full model lifecycle:
| `cog init` | Bootstrap a new model project |
| `cog build` | Create a container image |
| `cog predict` | Run a prediction in a container |
| `cog run` | Run arbitrary commands in a container |
| `cog exec` | Run arbitrary commands in a container |
| `cog serve` | Start HTTP server in a container |
| `cog push` | Deploy to Replicate |
| `cog login` | Authenticate with Replicate |
Expand Down Expand Up @@ -59,21 +59,21 @@ Input types are inferred from the schema:

---

### cog run
### cog exec

**Job**: Run arbitrary commands in a container.

```bash
cog run python -c "import torch; print(torch.cuda.is_available())"
cog run bash
cog exec python -c "import torch; print(torch.cuda.is_available())"
cog exec bash
```

Builds the image (if needed), starts a container, and runs the specified command inside it. Useful for:
- Debugging the container environment
- Running one-off scripts
- Interactive exploration

**Code**: `pkg/cli/run.go`
**Code**: `pkg/cli/exec.go`

---

Expand Down Expand Up @@ -210,7 +210,7 @@ pkg/cli/
├── root.go # Root command, subcommand registration
├── build.go # cog build
├── predict.go # cog predict
├── run.go # cog run
├── exec.go # cog exec
├── serve.go # cog serve
├── push.go # cog push
├── login.go # cog login
Expand Down
84 changes: 42 additions & 42 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ https://github.com/replicate/cog
**Examples**

```
To run a command inside a Docker environment defined with Cog:
$ cog run echo hello world
To execute a command inside a Docker environment defined with Cog:
$ cog exec echo hello world
```

**Options**
Expand Down Expand Up @@ -66,6 +66,46 @@ cog build [flags]
--use-cog-base-image Use pre-built Cog base image for faster cold boots (default true)
--use-cuda-base-image string Use Nvidia CUDA base image, 'true' (default) or 'false' (use python base image). False results in a smaller image but may cause problems for non-torch projects (default "auto")
```
## `cog exec`

Execute a command inside a Docker environment defined by cog.yaml.

Cog builds a temporary image from your cog.yaml configuration and runs the
given command inside it. This is useful for debugging, running scripts, or
exploring the environment your model will run in.

```
cog exec <command> [arg...] [flags]
```

**Examples**

```
# Open a Python interpreter inside the model environment
cog exec python

# Run a script
cog exec python train.py

# Run with environment variables
cog exec -e HUGGING_FACE_HUB_TOKEN=abc123 python download.py

# Expose a port (e.g. for Jupyter)
cog exec -p 8888 jupyter notebook
```

**Options**

```
-e, --env stringArray Environment variables, in the form name=value
-f, --file string The name of the config file. (default "cog.yaml")
--gpus docker run --gpus GPU devices to add to the container, in the same format as docker run --gpus.
-h, --help help for exec
--progress string Set type of build progress output, 'auto' (default), 'tty', 'plain', or 'quiet' (default "auto")
-p, --publish stringArray Publish a container's port to the host, e.g. -p 8000
--use-cog-base-image Use pre-built Cog base image for faster cold boots (default true)
--use-cuda-base-image string Use Nvidia CUDA base image, 'true' (default) or 'false' (use python base image). False results in a smaller image but may cause problems for non-torch projects (default "auto")
```
## `cog init`

Create a cog.yaml and predict.py in the current directory.
Expand Down Expand Up @@ -198,46 +238,6 @@ cog push [IMAGE] [flags]
--use-cog-base-image Use pre-built Cog base image for faster cold boots (default true)
--use-cuda-base-image string Use Nvidia CUDA base image, 'true' (default) or 'false' (use python base image). False results in a smaller image but may cause problems for non-torch projects (default "auto")
```
## `cog run`

Run a command inside a Docker environment defined by cog.yaml.

Cog builds a temporary image from your cog.yaml configuration and runs the
given command inside it. This is useful for debugging, running scripts, or
exploring the environment your model will run in.

```
cog run <command> [arg...] [flags]
```

**Examples**

```
# Open a Python interpreter inside the model environment
cog run python

# Run a script
cog run python train.py

# Run with environment variables
cog run -e HUGGING_FACE_HUB_TOKEN=abc123 python download.py

# Expose a port (e.g. for Jupyter)
cog run -p 8888 jupyter notebook
```

**Options**

```
-e, --env stringArray Environment variables, in the form name=value
-f, --file string The name of the config file. (default "cog.yaml")
--gpus docker run --gpus GPU devices to add to the container, in the same format as docker run --gpus.
-h, --help help for run
--progress string Set type of build progress output, 'auto' (default), 'tty', 'plain', or 'quiet' (default "auto")
-p, --publish stringArray Publish a container's port to the host, e.g. -p 8000
--use-cog-base-image Use pre-built Cog base image for faster cold boots (default true)
--use-cuda-base-image string Use Nvidia CUDA base image, 'true' (default) or 'false' (use python base image). False results in a smaller image but may cause problems for non-torch projects (default "auto")
```
## `cog serve`

Run a prediction HTTP server.
Expand Down
4 changes: 2 additions & 2 deletions docs/getting-started-own-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ torch==2.6.0

This will generate a Docker image with Python 3.13 and PyTorch 2 installed, for both CPU and GPU, with the correct version of CUDA, and various other sensible best-practices.

To run a command inside this environment, prefix it with `cog run`:
To run a command inside this environment, prefix it with `cog exec`:

```
$ cog run python
$ cog exec python
✓ Building Docker image from cog.yaml... Successfully built 8f54020c8981
Running 'python' in Docker with the current directory mounted as a volume...
────────────────────────────────────────────────────────────────────────────────────────
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ build:
Then, you can run any command inside this environment. For example, enter

```bash
cog run python
cog exec python

```

Expand Down
98 changes: 49 additions & 49 deletions docs/llms.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/notebooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ build:
Cog can run notebooks in the environment you've defined in `cog.yaml` with the following command:

```sh
cog run -p 8888 jupyter lab --allow-root --ip=0.0.0.0
cog exec -p 8888 jupyter lab --allow-root --ip=0.0.0.0
```

## Use notebook code in your predictor
Expand Down
2 changes: 1 addition & 1 deletion docs/yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ build:
gpu: true
```

When you use `cog run` or `cog predict`, Cog will automatically pass the `--gpus=all` flag to Docker. When you run a Docker image built with Cog, you'll need to pass this option to `docker run`.
When you use `cog exec` or `cog predict`, Cog will automatically pass the `--gpus=all` flag to Docker. When you run a Docker image built with Cog, you'll need to pass this option to `docker run`.

### `python_requirements`

Expand Down
4 changes: 2 additions & 2 deletions integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ Run a command with a pseudo-terminal (PTY), sending input from a file and captur

```txtar
# Run bash interactively with commands from input file
pty-run input.txt cog run $TEST_IMAGE /bin/bash
pty-run input.txt cog exec $TEST_IMAGE /bin/bash
stdout 'expected output'

# Run a simple command (no input needed)
pty-run /dev/null cog run $TEST_IMAGE echo "hello"
pty-run /dev/null cog exec $TEST_IMAGE echo "hello"
stdout 'hello'
```

Expand Down
Loading
Loading