Created
June 10, 2025 01:54
-
-
Save ka2n/994f8f635e3ab83b4c484a6a6576d723 to your computer and use it in GitHub Desktop.
docker compose: Create tmp files to retrieve external port from container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create port mapping files for each service/port combination | |
docker compose ps --format=json | jq -r ' | |
.Service as $service | | |
.Publishers[]? | | |
select(.PublishedPort > 0) | | |
"/tmp/compose_\($service)_\(.TargetPort)_\(.Protocol) \(.PublishedPort)" | |
' | while read -r filepath port; do | |
echo "$port" | docker compose exec -T <target> tee "$filepath" >/dev/null | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment