nginx - De l'intérieur d'un conteneur Docker, comment puis-je me connecter au localhost de la machine

Mots clés : nginxdockerreverse-proxydocker-networkingnginx

meilleur 4 Réponses nginx - De l'intérieur d'un conteneur Docker, comment puis-je me connecter au localhost de la machine

vote vote

95

[vagrant@docker:~] $ sudo ip addr show docker0 4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default     link/ether 56:84:7a:fe:97:99 brd ff:ff:ff:ff:ff:ff     inet 172.17.42.1/16 scope global docker0        valid_lft forever preferred_lft forever     inet6 fe80::5484:7aff:fefe:9799/64 scope link        valid_lft forever preferred_lft forever 
root@e77f6a1b3740:/# ip addr show eth0 863: eth0: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000     link/ether 66:32:13:f0:f1:e3 brd ff:ff:ff:ff:ff:ff     inet 172.17.1.192/16 scope global eth0        valid_lft forever preferred_lft forever     inet6 fe80::6432:13ff:fef0:f1e3/64 scope link        valid_lft forever preferred_lft forever 
root@e77f6a1b3740:/# route Kernel IP routing table Destination     Gateway         Genmask         Flags Metric Ref    Use Iface default         172.17.42.1     0.0.0.0         UG    0      0        0 eth0 172.17.0.0      *               255.255.0.0     U     0      0        0 eth0 
root@e77f6a1b3740:/# ping 172.17.42.1 PING 172.17.42.1 (172.17.42.1) 56(84) bytes of data. 64 bytes from 172.17.42.1: icmp_seq=1 ttl=64 time=0.070 ms 64 bytes from 172.17.42.1: icmp_seq=2 ttl=64 time=0.201 ms 64 bytes from 172.17.42.1: icmp_seq=3 ttl=64 time=0.116 ms 
[vagrant@docker:~] $ ip addr show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000     link/ether 08:00:27:98:dc:aa brd ff:ff:ff:ff:ff:ff     inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0        valid_lft forever preferred_lft forever     inet6 fe80::a00:27ff:fe98:dcaa/64 scope link        valid_lft forever preferred_lft forever 
[vagrant@docker:~] $ docker run --rm -it --network=host ubuntu:trusty ip addr show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000     link/ether 08:00:27:98:dc:aa brd ff:ff:ff:ff:ff:ff     inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0        valid_lft forever preferred_lft forever     inet6 fe80::a00:27ff:fe98:dcaa/64 scope link        valid_lft forever preferred_lft forever 
export DOCKER_HOST_IP=$(route -n | awk '/UG[ \t]/{print $2}') 
[vagrant@docker:~] $ docker run --rm -it --network=host mysql mysql -h 127.0.0.1 -uroot -p Enter password: Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 36 Server version: 5.5.41-0ubuntu0.14.04.1 (Ubuntu)  Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.  Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  mysql> 
vote vote

80

host.docker.internal 
localhost 
vote vote

76

ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1 
export DOCKERHOST=$(ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1) docker-compose -f docker-compose.yml up 
myapp:   build: .   ports:     - "80:80"   extra_hosts:     - "dockerhost:$DOCKERHOST" 
vote vote

67

/tmp/mysqld.sock /var/run/mysqld/mysqld.sock  /var/lib/mysql/mysql.sock /Applications/MAMP/tmp/mysql/mysql.sock # if running via MAMP 

Questions similaires