Docker启动容器抛出无法分配请求的地址错误

时间:2014-06-06 17:49:53

标签: postgresql ubuntu docker boot2docker

我在MAC OS主机上配置了一个ubuntu 12.04虚拟盒。 Docker在ubuntu上

我的以太网配置(桥接适配器)是

eth2      Link encap:Ethernet  HWaddr 08:00:27:f9:8f:77  
          inet addr:172.16.0.11  Bcast:172.16.255.255  Mask:255.255.0.0
          inet6 addr: fe80::a00:27ff:fef9:8f77/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:685 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:128864 (128.8 KB)

当我尝试启动postgresql容器时,得到以下错误。

sudo docker run -d -name="postgresql" -p 172.17.0.2:5432:5432 -v /data/sql:/data -e USER="username" -e DB="dbname" -e PASS="passwordname" paintedfox/postgresql
Warning: '-name' is deprecated, it will be replaced by '--name' soon. See usage.
WARNING: Local (127.0.0.1) DNS resolver found in resolv.conf and containers can't use it. Using default external servers : [8.8.8.8 8.8.4.4]
596355cf67dfe807f4e18cf341b3672eb0ab5e258f3fbbe332405ec101ea6949
2014/06/06 10:41:02 Error: Cannot start container 596355cf67dfe807f4e18cf341b3672eb0ab5e258f3fbbe332405ec101ea6949: listen tcp 172.17.0.2:5432: bind: cannot assign requested address

1 个答案:

答案 0 :(得分:1)

我认为您错误地使用了-p选项。

  

-p, - upload = []将容器的端口发布到主机                                 格式:ip:hostPort:containerPort | ip :: containerPort |                                               HOSTPORT:containerPort

看起来您正在尝试设置应该拥有主机IP的容器的IP

sudo docker run -d -name="postgresql" -p 5432:5432 -v /data/sql:/data -e USER="username" -e DB="dbname" -e PASS="passwordname" paintedfox/postgresql

sudo docker run -d -name="postgresql" -p 172.16.0.11:5432:5432 -v /data/sql:/data -e USER="username" -e DB="dbname" -e PASS="passwordname" paintedfox/postgresql

将端口5432发布到您系统的端口5432。

我认为你不能设置容器IP。