portscope is a lightweight Bash tool that checks your docker-compose.yml for host port conflicts before you run your stack.
Are you juggling tons of Docker Compose projects on your home server, laptop, or dev machineβ¦
and every new project opens yet another port?
And now you want to install even more?
π₯ Enter portscope β your port conflict detector.
It tells you before your container says "Port already in use".
- ποΈ Smart file selection:
- No argument? Uses current directory.
- Directory? Looks for
docker-compose.ymlinside. - File? Parses it directly as a Docker Compose file.
- π§ͺ Validates YAML file type.
- π Extracts host ports like
8080:80. β οΈ Detects conflicts with system ports (used by other services or Docker).- π« Ignores ports already used by containers from the same compose file.
- β Friendly output: βAll goodβ or conflict details.
- π Optionally free a specified port that's currently in use.
- π€ Non-interactive mode via
--yesorPORTSCOPE_YES=1.
curl -o portscope https://raw.githubusercontent.com/bnap00/portscope/main/portscope.sh
chmod +x portscope
sudo mv portscope /usr/local/bin/portscopeTo update later:
sudo curl -o /usr/local/bin/portscope https://raw.githubusercontent.com/bnap00/portscope/main/portscope.shportscope # Use current directory's docker-compose.yml
portscope /path/to/dir # Use compose file inside specified directory
portscope custom.yml # Parse a specific file directlyportscope --free-port 8080 # Try to free port 8080
portscope --free-port 8080 --yes # Free port 8080 without prompts
portscope --help # Show help message
portscope --version # Show version number$ portscope ./project
Using docker-compose file: ./project/docker-compose.yml
Required host ports: 80 6379
Info: Port 80 is already used by the same project β skipping
Conflict: Port 6379 is already in use by another containerUse this one-liner to list all unique host ports exposed by all running Docker containers:
docker ps --format '{{.Ports}}' | grep -oP '\d+(?=->)' | sort -n | uniqSimple. Fast. No surprises.
- Bash
ss(part ofiproute2package)- Docker CLI (optional for
--free-port)
- Add support for multiple compose files (e.g.,
-f a.yml -f b.yml) - Optional JSON output mode for CI
- Add CI integration and unit tests
We welcome feedback and PRs!
To propose improvements, please open an issue or submit a pull request.
MIT License