【发布时间】:2015-01-25 07:14:43
【问题描述】:
我已尝试关注some instructions on GitHub 设置端口转发,但我没有运气。你能帮忙吗?我按照书中的示例构建了容器,这里是 Dockerfile:
FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install -y nginx
RUN echo 'Hi, I am in your container' > /usr/share/nginx/html/index.html
EXPOSE 8000
采取的步骤:
$ boot2docker stop
$ VBoxManage modifyvm "boot2docker-vm" --natpf1 delete forwardHostPort8000ToDockerVM
$ VBoxManage modifyvm "boot2docker-vm" --natpf1 "forwardHostPort8000ToDockerVM,tcp,,8000,,8000"
$ boot2docker start
$ docker run -d -p 127.0.0.1:8000:8000 --name static_web static_web \nginx -g "daemon off;"
122ba8949685ce91b84890656c399b19028cb2e8a7e8be3d4a19122eba9ab592
这是结果:
$ curl 127.0.0.1:8000
curl: (52) Empty reply from server
$ telnet 127.0.0.1 8000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host
注意:
如果我不将其绑定到 127.0.0.1 接口(即仅-p 8000:8000),那么它将与我的 VM 的 IP 一起使用:
$ curl 192.168.59.103:8000
Hi, I am in your container
环境:
$ boot2docker -v
Boot2Docker-cli version: v1.3.1
Git commit: 57ccdb8
$ docker -v
Docker version 1.3.1, build 4e9bbfa
我使用的是在 OS X 10.10.1 下运行的 VirtualBox 4.3.20 版。
【问题讨论】:
-
感谢@alexwlchan 对格式的帮助。
标签: port boot2docker