block by drnic 78b92daeab0732ffb72b

Script to recreate docker containers to fix the host port to the current dynamically assigned port

Get the current running containers:

# docker --host unix:///var/vcap/sys/run/docker/docker.sock ps
CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS                  PORTS                                                                      NAMES
1795b5c8aa16        lnguyen/logstash:1.4   "/scripts/run.sh"   4 days ago          Up Less than a second   0.0.0.0:32768->514/tcp, 0.0.0.0:32769->9200/tcp, 0.0.0.0:32770->9300/tcp   cf-f9404974-4ff9-4658-96d1-4b165d8bf731   
7bd1c38e6c49        lnguyen/logstash:1.4   "/scripts/run.sh"   6 days ago          Up Less than a second   0.0.0.0:32771->514/tcp, 0.0.0.0:32772->9200/tcp, 0.0.0.0:32773->9300/tcp   cf-f99c81b2-efa7-4b90-a9d5-efa882e19875   

Install and run the fix script:

mkdir workspace
cd workspace
wget https://gist.github.com/drnic/78b92daeab0732ffb72b/download
mv download{,.tgz}
tar xfz download.tgz
cd gist78b92*
bundle
chmod +x fix_docker_host_ports.rb
DOCKER_URL=unix:///var/vcap/sys/run/docker/docker.sock bundle exec ./fix_docker_host_ports.rb

Gemfile

fix_docker_host_ports.rb