Exit code 1 is a generic error indicating that a Docker container's process terminated due to an application error or misconfiguration. This catch-all error can stem from incorrect Dockerfile references, missing dependencies, or runtime exceptions within the containerized application.
Exit code 1 is Docker's generic error code indicating that a container stopped unexpectedly due to an application-level failure. Unlike more specific exit codes (such as 137 for OOM kills or 139 for segmentation faults), exit code 1 serves as a catch-all for various issues including programming errors, missing files, configuration problems, or failed initialization. When a container exits with code 1, it means the main process (defined by CMD or ENTRYPOINT) encountered an error and terminated with a non-zero exit status. This is often the result of the application itself returning exit(1) or throwing an unhandled exception, rather than a Docker daemon or kernel-level issue.
The first step is to examine what the application logged before exiting. Use docker logs to view stdout and stderr:
docker ps -a
docker logs <container-id>Look for error messages, stack traces, or warnings that indicate what failed. Common patterns include "No such file or directory", "Permission denied", "ModuleNotFoundError", or database connection errors.
Ensure that your Dockerfile's CMD and ENTRYPOINT directives point to files that actually exist in the container:
# Check that these paths are correct
CMD ["/app/start.sh"]
ENTRYPOINT ["python", "app.py"]You can inspect the container filesystem to verify:
docker run --rm -it <image> /bin/sh
ls -la /app/If using a shell script as your entrypoint, ensure it's executable and has a proper shebang line:
# In Dockerfile, make script executable
COPY start.sh /app/start.sh
RUN chmod +x /app/start.shEnsure your script starts with:
#!/bin/bash
# or
#!/bin/shNote: Line endings matter. If you edited the script on Windows, convert CRLF to LF:
dos2unix start.shCheck that all runtime dependencies are present in the container. For Python:
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txtFor Node.js:
COPY package*.json .
RUN npm ci --only=productionUse multi-stage builds to keep the final image clean while ensuring all build dependencies are available during compilation.
Run your application outside of Docker to isolate whether the issue is container-specific:
# For Python
python app.py
# For Node.js
node server.jsIf it works locally but fails in Docker, the issue is likely related to:
- Missing files not copied into the image
- Different environment variables
- Path differences (/app vs relative paths)
- Missing system packages
Ensure all required environment variables are set and accessible:
# Pass environment variables at runtime
docker run -e DATABASE_URL=postgres://... <image>
# Or use an env file
docker run --env-file .env <image>In docker-compose.yml:
services:
app:
environment:
- DATABASE_URL=${DATABASE_URL}
- API_KEY=${API_KEY}
# or
env_file:
- .envAdd debug logging to verify environment variables are loaded correctly.
Sometimes container state becomes corrupted. Stop, remove, and recreate the container:
# Stop and remove container
docker stop <container-id>
docker rm <container-id>
# Remove the image and rebuild
docker rmi <image>
docker build -t <image> .
docker run <image>For docker-compose:
docker-compose down
docker-compose up --buildWhen debugging exit code 1 in production environments, consider implementing health checks and readiness probes to catch initialization failures early. In Kubernetes, use kubectl describe pod to view detailed event logs and exit codes. For recurring exit code 1 issues, implement structured logging with correlation IDs to trace the exact failure point. Consider using Docker's --init flag to properly handle signals and zombie processes, as improper signal handling can sometimes manifest as exit code 1. For CI/CD pipelines, temporarily add set -x to shell scripts or increase application log verbosity to capture more context about failures. Memory constraints can also cause applications to exit with code 1 before triggering an OOM kill (exit 137), so monitor container resource usage with docker stats.
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