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.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/replicate/cog/llms.txt
Use this file to discover all available pages before exploring further.
Usage
Flags
Environment variables in the form
name=value. Can be specified multiple times.Publish a container’s port to the host (e.g.,
-p 8000). Can be specified multiple times.The name of the config file
GPU devices to add to the container, in the same format as
docker run --gpusSet type of build progress output:
auto, tty, plain, or quietUse pre-built Cog base image for faster cold boots
Use Nvidia CUDA base image:
true, false, or autoExamples
Open a Python interpreter
Run a script
- All dependencies from
cog.yamlinstalled - Current directory mounted at
/src - GPU access (if configured)
Run with environment variables
- Passing API tokens
- Setting debug flags
- Configuring cache directories
Expose a port (Jupyter notebook)
http://localhost:8888.
Output:
Expose multiple ports
Run bash commands
Run with GPU access
Run an interactive bash shell
Run tests
Download model weights
Run data preprocessing
Common Use Cases
Development and debugging
Test your code in the exact environment where it will run:Interactive exploration
Explore the environment interactively:Running Jupyter notebooks
Develop in Jupyter with your exact dependencies:Training and experimentation
Run training scripts with environment isolation:How It Works
-
Build phase:
- Reads your
cog.yaml - Builds a temporary Docker image
- Installs all dependencies
- Reads your
-
Run phase:
- Starts a Docker container
- Mounts current directory at
/src - Sets working directory to
/src - Runs your command
- Streams output to your terminal
-
Cleanup:
- Container stops when command exits
- Exit code matches your command’s exit code
Volume Mounting
Your current directory is automatically mounted at/src in the container:
- Read access: Access all your source files
- Write access: Changes persist to your local filesystem
- Working directory: Commands run in
/srcby default
Environment Variables
Automatic propagation
Cog automatically propagates:RUST_LOG- For debugging the Cog runtime
Manual environment variables
Pass environment variables with-e:
From cog.yaml
Environment variables can also be set incog.yaml:
GPU Access
Automatic GPU detection
Ifcog.yaml specifies gpu: true, Cog automatically:
- Adds
--gpus allto the container - Uses CUDA base images
- Installs GPU-enabled packages
Manual GPU control
Check GPU availability
Port Publishing
Publish ports to access services running in the container:-p <host_port> where the container port matches the host port.
Working Directory
Commands run in/src, which is mounted to your current directory:
Exit Codes
The exit code matches your command’s exit code:Comparison with Docker
With cog run:
Equivalent Docker command:
See Also
- cog predict - Run predictions on your model
- cog serve - Start an HTTP server
- cog build - Build a Docker image
- cog.yaml reference - Configuration file format