Boot2Docker: unable to redirect ports to work

I play with boot2docker (docker 1.6) on windows 8.1. I wanted to make myself a container for the machine to play with ruby, and I want to be able to connect to the rails server from my Windows host. To start with small steps, first I want to connect to my container from my bootable virtual machine. I attach the docker file below, it builds without problems, and I can run the container from it. I do it like this:

docker run -it -p 3000:3000 3564860f7afd /bin/bash 

Then in this container I say:

 cd ~/myapp && bundle exec rails server -d 

And to see if everything works:

 ~/myapp$ sudo apt-get install wget && wget localhost:3000 

and I get http 500, this is normal, I just wanted to check if the server is working. Then I exit using ctrl + p, ctrl + q. But then on boot2docker I do agin

 wget localhost:3000 

and get

 Connecting to localhost:3000 (127.0.0.1:3000) wget: error getting response: Connection reset by peer 

So, it seems that port 3000 is incorrectly redirected to boot2docker VM. What have I done wrong? What am I missing? I searched Google many times and tried a couple of things, such as explicitly expanding the port from the docker file or adding the -P switch to run, but I always end up the same way - it doesn't work.

Any help would be greatly appreciated.

UPDATE 05/02/2015

I also tried the things described in a comment by Markus Mahlberg and a response from VonC. My VM configuration seems to be in order, I also checked in the VirtualBox GUI, and that seems fine. Additional Information: When I Start

 boot2docker ssh -vnNTL 3000:localhost:3000 

and then open localhost: 3000 on my Windows host, which I see in the trace logs in the boot2docker console, they look like this:

 debug1: channel 1: free: direct-tcpip: listening port 3000 for localhost port 3000, connect from 127.0.0.1 port 50512 to 127.0.0.1 port 3000, nchannels 3 

Chrome tells me that the answer was empty. From checking the logs on the container, I know that the request never reached it.

End of update

Update 05/03/2015

It seems to me that my problem is not so much connected with boot2docker or docker as with my computer configuration. I have tested docker / boot2docker configuration many times, which is unlikely that I made a mistake there.

Desperately I reinstalled boot2docker and VirtualBox, still no effects. Any debugging ideas what might be wrong in my configuration? Just another idea - try to do the same on another machine. But even if it works, my original problem is no less annoying.

End of update

Here is my docker file:

 FROM ubuntu MAINTAINER anonymous <anonymous@localhost.com> LABEL Description="Ruby container" # based on https://gorails.com/setup/ubuntu/14.10 RUN apt-get update RUN apt-get -y upgrade RUN apt-get -y install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \ && groupadd anonymous \ && useradd anonymous -m -g anonymous -g sudo ENV HOME /home/anonymous USER anonymous RUN git clone https://github.com/sstephenson/rbenv.git ~/.rbenv RUN echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc RUN echo 'eval "$(rbenv init -)"' >> ~/.bashrc RUN exec $SHELL RUN git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build RUN echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc RUN exec $SHELL RUN git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash ENV PATH "$HOME/.rbenv/bin:$HOME/.rbenv/plugins/ruby-build/bin:$PATH" RUN rbenv install 2.2.1 RUN rbenv global 2.2.1 ENV PATH "$HOME/.rbenv/shims:$PATH" RUN echo 'gem: --no-ri --no-rdoc' > ~/.gemrc RUN gem install bundler RUN git config --global color.ui true RUN git config --global user.name "mindriven" RUN git config --global user.email "3dcreator.pl@gmail.com" RUN ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa -C "3dcreator.pl@gmail.com" RUN sudo apt-get -qy install software-properties-common python-software-properties RUN sudo add-apt-repository ppa:chris-lea/node.js RUN sudo apt-get -y install nodejs RUN gem install rails -v 4.2.0 RUN ~/.rbenv/bin/rbenv rehash RUN rails -v RUN sudo apt-get -qy install mysql-server mysql-client RUN sudo apt-get install libmysqlclient-dev RUN rails new ~/myapp -d mysql RUN sudo /etc/init.d/mysql start && cd ~/myapp && rake db:create 
+3
windows docker boot2docker forwarding ports
May 01 '15 at 19:03
source share
2 answers

See Boot2docker Workarounds :

You can use the VBoxManage.exe commands to open these ports at the VM level of the boot disk so that your virtual host can access them.
By default, only port 2222 is open for boot2docker ssh to work and to open an interactive ssh boot2docker session.
Just make sure that VirtualBox is in your PATH .

  • VBoxManage modifyvm : works when VM2 boot2docker is not already running, or after boot2docker stop ,
  • VBoxManage controlvm : works when VM2 boot2docker is running, after boot2docker start .

Let's say your Docker container provides port 8000, and you want to access it from other computers on the local network. You can do this temporarily using ssh:

Run the following command (and save it):

 $ boot2docker ssh -vnNTL 8000:localhost:8000 

or you can configure port forwarding for NAT VirtualBox:

 $ VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port8000,tcp,,8000,,8000"; 

If vm is already running, you should run this other command:

 $ VBoxManage controlvm "boot2docker-vm" natpf1 "tcp-port8000,tcp,,8000,,8000"; 

Now you can access your container from your host computer in

 localhost:8000 

So you don’t have to bother with the VirtualBox GUI by selecting a computer called boot2docker-vm from the list on the left, selecting Settings from the Machine menu (or press Command - S on Mac), selecting the Network icon at the top, and finally clicking the Port Forwarding button .

+3
May 2 '15 at 4:44
source share

boot2docker on Windows (and OSX) runs the VM virtual machine with Linux. By default, it provides only the ports needed for ssh in the VM. You will need to change the virtual machine so that it displays more ports.

Adding ports to the virtual machine is more about configuring VirtualBox and less about boot2docker (this is a VM property, not the software running inside it). See the VirtualBox documentation for “port forwarding” and other network configurations. https://www.virtualbox.org/manual/ch06.html

+1
May 01 '15 at 23:04
source share



All Articles