这样的简单设置:
docker-compose build && docker-compose run web ping db
如果我跑:
Starting myapp_db_1
ping: unknown host
我得到:
docker-compose run cat /etc/hosts
为什么呢? 如果我跑:
Starting myapp_db_1
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 4af9653f843a
我明白这一点:
public static ObjectA newObjectA(String param) {
if (param == null) {
return null;
}
ObjectB objB = new ObjectB(); // Occupied the memory required by for member variables of ObjectB along with the references
ObjectA objA; // Occupy 4 bytes or 8 bytes as explained below.
// do something else
return objA;
}
(每次运行时值4af9653f843a发生变化)
我在mac os x上使用docker-compose 1.6.2和docker version 1.10.3(所以也是虚拟框)
为什么会这样?如何通过主机名访问Web容器中的db容器?
答案 0 :(得分:0)
好吧,我刚刚意识到我需要运行
docker-compose up
在我可以ping之前至少一次