Fix port check: only allow our own compose containers, not any Docker
Previously any Docker process on the port was treated as safe. Now uses docker inspect on our project's containers specifically, so ports used by other apps on the server trigger the conflict prompt. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e33fec5353
commit
1fe15a1cec
1 changed files with 10 additions and 6 deletions
16
deploy.sh
16
deploy.sh
|
|
@ -88,13 +88,17 @@ check_port() {
|
|||
return
|
||||
fi
|
||||
|
||||
# Check if it belongs to our own docker containers
|
||||
local proc_name
|
||||
proc_name=$(cat "/proc/${pid}/comm" 2>/dev/null || echo "unknown")
|
||||
# Check if it belongs to OUR docker-compose project (not other apps on server)
|
||||
local our_ids
|
||||
our_ids=$(docker compose -f docker-compose.yml -f docker-compose.prod.yml ps -q 2>/dev/null || true)
|
||||
|
||||
if [[ "$proc_name" == "docker"* ]] || [[ "$proc_name" == "containerd"* ]]; then
|
||||
info " Port $port ($service): used by Docker (will be replaced on restart)"
|
||||
return
|
||||
if [[ -n "$our_ids" ]]; then
|
||||
# shellcheck disable=SC2086
|
||||
if docker inspect $our_ids 2>/dev/null \
|
||||
| grep -q "\"HostPort\": \"${port}\""; then
|
||||
info " Port $port ($service): used by our container (will be replaced on restart)"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
warn " Port $port ($service) is in use by PID $pid ($proc_name)"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue