Created
August 1, 2014 13:11
-
-
Save simota/2b183df853e01c7e4741 to your computer and use it in GitHub Desktop.
VM上のDockerコンテナに固定ipを割り振ってホスト側から接続出来るようにする ref: http://qiita.com/simota/items/06ad3400224e98d43fc5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| HOST: Mac OSX 10.9 | |
| Docker HOST: ubuntu 14.0.4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ ADAPTER=$(VBoxManage hostonlyif create | egrep -o "vboxnet[0-9]+") | |
| $ VBoxManage hostonlyif ipconfig $ADAPTER --ip 192.168.56.1 --netmask 255.255.255.0 | |
| $ VBoxManage dhcpserver add --ifname $ADAPTER --ip 192.168.56.100 --netmask 255.255.255.0 --lowerip 192.168.56.101 --upperip 192.168.56.254 | |
| $ VBoxManage dhcpserver modify --ifname $ADAPTER --enable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ ssh [email protected] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ sed -i -e 's/DOCKER_OPTS=/DOCKER_OPTS="-H=tcp:\/\/0.0.0.0:4243"/g' /etc/init/docker.conf | |
| $ service docker restart |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export DOCKER_HOST=tcp://192.168.56.254:4243 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ vagrant box add ubuntu-14.04-amd64-vbox https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-14.04-amd64-vbox.box | |
| $ mkdir ubuntu-docker | |
| $ cd ubuntu-docker | |
| $ vagrant init ubuntu-14.04-amd64-vbox | |
| $ sed -i "" -e 's/# config.vm.network "private_network", ip: "192.168.33.10"/config.vm.network "private_network", ip: "192.168.56.254"/g' ./Vagrantfile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ vagrant up | |
| $ vagrant ssh | |
| $ sudo su | |
| $ apt-get install -y bridge-utils arping | |
| $ curl -sSL https://get.docker.io/ubuntu/ | sudo sh | |
| $ sed -i -e '$d' /etc/rc.local | |
| $ echo "/sbin/brctl addbr docker1" >> /etc/rc.local | |
| $ echo "/sbin/ip addr add 192.168.0.1/24 dev docker1" >> /etc/rc.local | |
| $ echo "/sbin/ifconfig docker1 up" >> /etc/rc.local | |
| $ echo "/sbin/iptables -t nat -A POSTROUTING -s 192.168.0.0/24 ! -d 192.168.0.0/24 -j MASQUERADE" >> /etc/rc.local | |
| $ echo "exit 0" >> /etc/rc.local |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ cd /usr/local/bin | |
| $ wget https://raw.githubusercontent.com/jpetazzo/pipework/master/pipework | |
| $ chmod +x pipework |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ vagrant reload |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ sudo route add -net 192.168.0.0/24 192.168.56.254 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ docker pull sylvainlasnier/ssh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ CID=$(docker run -d sylvainlasnier/ssh) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ pipework docker1 $CID 192.168.0.2/[email protected] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment