Created
March 12, 2016 15:01
-
-
Save maxwellimpact/29bd907059156a350153 to your computer and use it in GitHub Desktop.
How to assign a specific IP to a Docker Container
This file contains 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 /usr/bin/env ruby | |
# ----------------------- | |
# DOCKER IPS | |
#------------------------ | |
# get the default docker info | |
system "eval $(docker-machine env)" | |
docker_ip = %x(docker-machine ip) | |
# get a container ip based on the main docker ip | |
# guessing the use of 100 since its standard | |
# swapping with a custom container ip ending in 110 | |
container_ip = docker_ip.sub(/100\n/, '110') | |
# set the ip in the docker machine | |
system "docker-machine ssh default 'sudo ifconfig eth1:1 "+container_ip+" netmask 255.255.255.0 up'" | |
# setup the hosts file | |
system("sudo ruby docker_setup_hosts.rb " + container_ip) | |
# ----------------------- | |
# BUILD & RUN | |
#------------------------ | |
system "docker build -t joncox/example ." | |
container_id = %x(docker run -itd -p #{container_ip}:80:80 -p #{container_ip}:443:443 -v #{Dir.pwd}:/path/to/app joncox/example) | |
system "docker exec -it "+container_id.sub(/\n/,'')+" bash -c '/path/to/app/scripts/on_install.dev.sh'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment