gpt4 book ai didi

docker - 无法 ping docker 容器

转载 作者:行者123 更新时间:2023-12-04 19:51:40 25 4
gpt4 key购买 nike

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

编辑

我无法ping通机器。我可以运行镜像并在 ps 命令中查看容器。我也可以执行 bash 进入它。

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 -i s#/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": {}
}
}
]

最佳答案

如“Can't visit http://172.17.0.2:5000 after starting docker registry ”中所述,您不能使用为 container-to-container communication 制作的内部 IP。 .

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

2017 年 2 月更新,docker 1.13+:作为 commentedkboom , 你现在有 Docker for Mac它使用轻量级管理程序 (HyperKit),允许绑定(bind)到 localhost (但您仍然无法访问内部地址)。

关于docker - 无法 ping docker 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34212236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com