Skip to content

Instantly share code, notes, and snippets.

@pantasio
Forked from zainengineer/container_ip.bash
Created September 2, 2019 19:14
Show Gist options
  • Save pantasio/2931157dfc47a7b381569473dcff7278 to your computer and use it in GitHub Desktop.
Save pantasio/2931157dfc47a7b381569473dcff7278 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