Docker exit code 125 occurs when the docker run command itself fails before the container can start. This typically indicates a problem with the Docker daemon, invalid command syntax, or system resource conflicts.
Exit code 125 is Docker's way of signaling that the `docker run` command failed at the daemon level, before the container could even start executing. Unlike exit codes from the container itself (which indicate application failures), exit code 125 means Docker encountered a problem with how the container was being launched. This error originates from the Docker daemon and indicates one of several possible issues: invalid command-line flags, permission problems, resource conflicts, or missing prerequisites. The actual root cause is often revealed in the full error message that accompanies the exit code. Understanding exit code 125 is important because it requires troubleshooting Docker's configuration and environment, rather than the application inside the container.
First, verify the Docker daemon is active and responding:
# On Linux
sudo systemctl status docker
# Or try
docker infoIf Docker is not running, start it:
# On Linux
sudo systemctl start docker
# On Mac/Windows
# Start Docker Desktop applicationExecute your docker run command directly in the terminal to see the complete error message. Exit code 125 is generic, but the accompanying message reveals the actual problem:
docker run [your-options] [image-name]Look for specific errors like:
- "Conflict. The container name is already in use"
- "Invalid address X.X.X.X: It does not belong to any of this network's subnets"
- "Range of CPUs is from 0.01 to X.XX, as there are only X CPUs available"
- "user declined directory sharing"
If the error mentions a container name conflict, list and remove the existing container:
# List all containers (including stopped ones)
docker ps -a
# Remove the conflicting container
docker rm <container-name>
# Or remove all stopped containers
docker container pruneTo prevent this issue, use the --rm flag to automatically remove containers on exit:
docker run --rm [other-options] [image-name]Check if the Docker image exists locally:
docker imagesIf the image is missing (possibly removed by docker system prune), pull it again:
docker pull [image-name]If the error mentions network problems:
# List networks
docker network ls
# Inspect the network
docker network inspect [network-name]
# Remove and recreate if needed
docker network rm [network-name]
docker network create [network-name]If manually specifying an IP address, ensure it belongs to the network's subnet range.
On Windows or Mac, if you see "user declined directory sharing":
1. Open Docker Desktop
2. Go to Settings → Resources → File Sharing
3. Add the directory path that contains your volumes or bind mounts
4. Click "Apply & Restart"
On Windows, ensure the drive is shared in Docker Desktop settings.
If the error mentions CPU constraints, either:
Option 1: Reduce the CPU limit in your docker run command:
docker run --cpus="1.0" [image-name]Option 2: Increase Docker Desktop's CPU allocation (Mac/Windows):
1. Open Docker Desktop → Settings → Resources
2. Increase CPUs and Memory sliders
3. Apply & Restart
If none of the above work, try resetting Docker:
# Restart Docker daemon (Linux)
sudo systemctl restart docker
# Or reset containers and networks
docker container prune
docker network prune
docker volume pruneOn Docker Desktop (Mac/Windows), use "Troubleshoot → Reset to factory defaults" as a last resort (this will remove all containers, images, and volumes).
Understanding Docker Exit Codes: Exit codes 125-127 are reserved for Docker daemon errors, not application errors. Exit code 125 specifically means docker run failed, exit code 126 means the container command can't be invoked (not executable), and exit code 127 means the command wasn't found.
Windows-Specific Issues: Windows containers switching to Linux containers or vice versa can cause exit code 125. You may need to switch container modes in Docker Desktop and restart.
Hyper-V/Virtualization: On Windows, exit code 125 can occur if Hyper-V or WSL 2 backend is not properly configured. Ensure virtualization is enabled in BIOS and the required Windows features are installed.
CI/CD Environments: In automated pipelines, exit code 125 often indicates missing configuration (environment variables, secrets, network access). Check that the CI runner has proper Docker daemon access and sufficient resources.
Repository Name Validation: Docker requires repository names to be lowercase. If your project name or image tag contains uppercase letters, you'll get exit code 125 with "invalid reference format". Always use lowercase in image names.
image operating system "linux" cannot be used on this platform
How to fix 'image operating system linux cannot be used on this platform' in Docker
manifest unknown: manifest unknown
How to fix 'manifest unknown' in Docker
cannot open '/etc/passwd': Permission denied
How to fix 'cannot open: Permission denied' in Docker
Error response from daemon: failed to create the ipvlan port
How to fix 'failed to create the ipvlan port' in Docker
toomanyrequests: Rate exceeded for anonymous users
How to fix 'Rate exceeded for anonymous users' in Docker Hub