Skip to content

Instantly share code, notes, and snippets.

@zainengineer
Last active February 2, 2023 21:20
Show Gist options
  • Save zainengineer/6722174f6cb68080ae197fc757519f38 to your computer and use it in GitHub Desktop.
Save zainengineer/6722174f6cb68080ae197fc757519f38 to your computer and use it in GitHub Desktop.
Get docker container ip
#!/usr/bin/env bash
#inside docker container
HOST_IP=$(/sbin/ip route|awk '/default/ { print $3 }')
CONTAINER_IP=$(curl "$HOST_IP:8000" 2>/dev/null)
echo "container ip is $CONTAINER_IP"
#!/usr/bin/env bash
#then run something like this inside ./host
php -S 0.0.0.0:8000
#!/bin/env php
# ./host/index.php on host
echo $_SERVER['REMOTE_ADDR'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment