无法ping通docker容器

新的docker在mac osx上。 我正在从基础phusion映像构build一个Ubuntu映像作为一个git服务器使用。 使用以下文件来安装基本和所需的软件。 这很好。 但是,我无法ping通机器。

编辑


我无法ping通机器。 我可以运行该图像,并在ps命令中查看容器。 我也可以执行它。

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 54e4cef78445 git-ssh_img "/usr/sbin/sshd -D" 44 minutes ago Up 44 minutes 22/tcp git-ssh 

以下也有效

 docker exec -it 54e4cef78445 ping www.google.com PING www.google.com (173.194.219.147) 56(84) bytes of data. 64 bytes from ya-in-f147.1e100.net (173.194.219.147): icmp_seq=1 ttl=61 time=65.1 ms 64 bytes from ya-in-f147.1e100.net (173.194.219.147): icmp_seq=2 ttl=61 time=67.1 ms 

Dockerfile:

 # Use phusion/baseimage as base image. To make your builds reproducible, make # sure you lock down to a specific version, not to `latest`! # See https://github.com/phusion/baseimage-docker/blob/master/Changelog.md for # a list of version numbers. FROM phusion/baseimage:0.9.18 # Use baseimage-docker's init system. CMD ["/sbin/my_init"] # ...put your own build instructions here... ENV TERM xterm RUN apt-get -y update RUN apt-get -y install openssh-server RUN apt-get -y install git \ libxml2-dev \ python \ build-essential \ make \ gcc \ python-dev \ python-pip # Clean up APT when done. RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* # Setting openssh # RUN mkdir /var/run/sshd RUN sed -i "s/#PasswordAuthentication yes/PasswordAuthentication no/" /etc/ssh/sshd_config # Adding git user RUN adduser --system git RUN mkdir -p /home/git/.ssh # Clearing and setting authorized ssh keys RUN echo '' > /home/git/.ssh/authorized_keys RUN echo 'First key' >> /home/git/.ssh/authorized_keys # RUN echo 'Second SSH public key' >> /home/git/.ssh/authorized_keys # ... # Updating shell to bash RUN sed -is#/home/git:/bin/false#/home/git:/bin/bash# /etc/passwd EXPOSE 22 CMD ["/usr/sbin/sshd", "-D"] 

检查命令:

 [ { "Id": "54e4cef78445e1308b744297edc1d3d153932ce7724e87b35dc3690f8ffe41a2", "Created": "2015-12-10T21:01:16.683875853Z", "Path": "/usr/sbin/sshd", "Args": [ "-D" ], "State": { "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 13930, "ExitCode": 0, "Error": "", "StartedAt": "2015-12-10T21:01:16.763739339Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "b2c6f9604ceca1e112dc0560aa4d0c50596d27c80256c544613f1d6badf6ccda", "NetworkSettings": { "Bridge": "", "EndpointID": "87f12f9b527f3e0d7f823f1e2c88b0d0e860ff2d1687568d0a15cfa9fdfe22c3", "Gateway": "172.17.42.1", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "HairpinMode": false, "IPAddress": "172.17.0.26", "IPPrefixLen": 16, "IPv6Gateway": "", "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:1a", "NetworkID": "a60ea78a8239baed013f9bfb1b2719a599ddef7745170e3c17eeab743a391ebe", "PortMapping": null, "Ports": { "22/tcp": null }, "SandboxKey": "/var/run/docker/netns/54e4cef78445", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null }, "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/54e4cef78445e1308b744297edc1d3d153932ce7724e87b35dc3690f8ffe41a2/resolv.conf", "HostnamePath": "/mnt/sda1/var/lib/docker/containers/54e4cef78445e1308b744297edc1d3d153932ce7724e87b35dc3690f8ffe41a2/hostname", "HostsPath": "/mnt/sda1/var/lib/docker/containers/54e4cef78445e1308b744297edc1d3d153932ce7724e87b35dc3690f8ffe41a2/hosts", "LogPath": "/mnt/sda1/var/lib/docker/containers/54e4cef78445e1308b744297edc1d3d153932ce7724e87b35dc3690f8ffe41a2/54e4cef78445e1308b744297edc1d3d153932ce7724e87b35dc3690f8ffe41a2-json.log", "Name": "/git-ssh", "RestartCount": 0, "Driver": "aufs", "ExecDriver": "native-0.2", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": null, "ContainerIDFile": "", "LxcConf": [], "Memory": 0, "MemorySwap": 0, "CpuShares": 0, "CpuPeriod": 0, "CpusetCpus": "", "CpusetMems": "", "CpuQuota": 0, "BlkioWeight": 0, "OomKillDisable": false, "MemorySwappiness": -1, "Privileged": false, "PortBindings": {}, "Links": null, "PublishAllPorts": false, "Dns": null, "DnsSearch": null, "ExtraHosts": null, "VolumesFrom": null, "Devices": [], "NetworkMode": "default", "IpcMode": "", "PidMode": "", "UTSMode": "", "CapAdd": null, "CapDrop": null, "GroupAdd": null, "RestartPolicy": { "Name": "no", "MaximumRetryCount": 0 }, "SecurityOpt": null, "ReadonlyRootfs": false, "Ulimits": null, "LogConfig": { "Type": "json-file", "Config": {} }, "CgroupParent": "", "ConsoleSize": [ 0, 0 ] }, "GraphDriver": { "Name": "aufs", "Data": null }, "Mounts": [], "Config": { "Hostname": "54e4cef78445", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": true, "AttachStderr": true, "ExposedPorts": { "22/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "TERM=xterm" ], "Cmd": [ "/usr/sbin/sshd", "-D" ], "Image": "git-ssh_img", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": {} } } ] 

如“ 启动dockerregistry后不能访问http://172.17.0.2:5000 ”所述,您不能使用为容器到容器通信所做的内部IP。

您需要使用由$(docker-machine ip <yourMachine>)返回的IP来真正ping运行您的容器的机器。


更新到2017年2月,docker 1.13+:如kboom 评论 ,您现在已经有了Docker for Mac ,它使用轻量级Hypervisor( HyperKit ),允许绑定到localhost (但仍然无法访问内部地址)。