Docker

Goal

Internet -> Localhost running debian -> Launch Containers -> Assign Routable IP

Step 1

docker images

root@f4c03737ab09:/# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu/withwebserver version1 2a53597718ae 38 minutes ago 231.7 MB

Run the docker image with webserver

docker run -p 91:91 -i -t -d 2a53597718ae /bin/bash

Attach to the specific image

docker exec -i -t f4c03737ab09 /bin/bash

Once we are on the specific image lets go ahead and configure wordpress and mariadb for our purpose.

root@f4c03737ab09:/#

Type ifconfig inside the container

inet addr:172.17.0.68

http://blog.codeaholics.org/2013/giving-dockerlxc-containers-a-routable-ip-address/

From the above site i wrote this nifty script just pass in the ip of the container and you will always have a IP that will be available internally.

root@inkarma:~# ./assign_ip_2_docker.sh 172.17.0.68

root@inkarma:~# cat assign_ip_2_docker.sh
#!/bin/bash
iptables -t nat -A PREROUTING -p all -d $1 -j BRIDGE-VIRTUAL0
iptables -t nat -A OUTPUT -p all -d $1 -j BRIDGE-VIRTUAL0
iptables -t nat -A BRIDGE-VIRTUAL0 -p all -j DNAT –to-destination $1
root@inkarma:~#

 

Test from browser

http://172.17.0.68:91/

Your website should appear.

Save the image for later use.

docker commit f4c03737ab09 ubuntu/withwebserver:version2

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s