-1

I have tried to follow some instructions on GitHub to set up the port forwarding but I have no luck. Would you please help? I built the container following an example in a book and here is the 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   

Steps taken:

$ 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

This is the result:

$ 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

Note: If I don't bind it to the 127.0.0.1 interface (i.e, only -p 8000:8000), then it will work with my VM’s IP:

$ curl 192.168.59.103:8000
Hi, I am in your container

Env:

$ boot2docker -v
Boot2Docker-cli version: v1.3.1
Git commit: 57ccdb8

$ docker -v
Docker version 1.3.1, build 4e9bbfa

I'm using VirtualBox version 4.3.20 running under OS X 10.10.1.

alexwlchan
  • 5,699
  • 7
  • 38
  • 49
skwokie
  • 425
  • 1
  • 6
  • 20

1 Answers1

0

It is actually a bug on my side. I exposed port 8000 in the Dockerfile; however, I haven't changed the setting in nginx. So, I changed it back to port 80 and started the container as followed, and it worked. Now I can hit it with a browser on another machine.

    docker run -d -p 8000:80 --name static_web static_web \nginx -g "daemon off;"
skwokie
  • 425
  • 1
  • 6
  • 20