|
#!/usr/bin/env ruby |
|
|
|
# DOCKER_URL=unix:///var/vcap/sys/run/docker/docker.sock bundle exec ./fix_docker_host_ports.rb |
|
|
|
# curl http://containers:[email protected]/v2/service_instances/$RANDOM -d '{ |
|
# "service_id": "2fd814ac-d1f7-4d4a-a4f7-d386cd8fd8e3", |
|
# "plan_id": "1a0efffc-eb45-4bf8-8ee3-a3c1a9a53151", |
|
# "organization_guid": "org-guid-here", |
|
# "space_guid": "space-guid-here" |
|
# }' -X PUT -H "X-Broker-API-Version: 2.4" -H "Content-Type: application/json" |
|
|
|
# docker --host unix:///var/vcap/sys/run/docker/docker.sock ps -a |
|
# CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
|
# 767a17b0b3c1 frodenas/postgresql:latest "/scripts/run.sh " 2 seconds ago Up 1 seconds 0.0.0.0:32772->5432/tcp cf-foobar |
|
# 38bd802ee1c9 frodenas/postgresql:latest "/scripts/run.sh " 18 seconds ago Up 17 seconds 0.0.0.0:32769->5432/tcp happy_bell |
|
# a4c72c1c504e frodenas/postgresql:latest "/scripts/run.sh " 19 seconds ago Up 18 seconds 0.0.0.0:32770->5432/tcp dreamy_sinoussi |
|
# ef75144ade79 frodenas/postgresql:latest "/scripts/run.sh " 19 seconds ago Up 18 seconds 0.0.0.0:32771->5432/tcp backstabbing_engelbart |
|
|
|
# DOCKER_URL=unix:///var/vcap/sys/run/docker/docker.sock bundle exec ./fix_docker_host_ports.rb |
|
# Removing container /cf-foobar |
|
# Recreating container /cf-foobar |
|
# Restarting container /cf-foobar with ports {"5432/tcp"=>[{"HostIp"=>"0.0.0.0", "HostPort"=>"32772"}]} |
|
# Removing container /happy_bell |
|
# Recreating container /happy_bell |
|
# Restarting container /happy_bell with ports {"5432/tcp"=>[{"HostIp"=>"0.0.0.0", "HostPort"=>"32769"}]} |
|
# Removing container /dreamy_sinoussi |
|
# Recreating container /dreamy_sinoussi |
|
# Restarting container /dreamy_sinoussi with ports {"5432/tcp"=>[{"HostIp"=>"0.0.0.0", "HostPort"=>"32770"}]} |
|
# Removing container /backstabbing_engelbart |
|
# Recreating container /backstabbing_engelbart |
|
# Restarting container /backstabbing_engelbart with ports {"5432/tcp"=>[{"HostIp"=>"0.0.0.0", "HostPort"=>"32771"}]} |
|
|
|
# docker --host unix:///var/vcap/sys/run/docker/docker.sock ps -a |
|
# CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
|
# a9e32efb1d29 frodenas/postgresql:latest "/scripts/run.sh " 4 seconds ago Up 3 seconds 0.0.0.0:32771->5432/tcp backstabbing_engelbart |
|
# e86a680422c4 frodenas/postgresql:latest "/scripts/run.sh " 4 seconds ago Up 3 seconds 0.0.0.0:32770->5432/tcp dreamy_sinoussi |
|
# 13a9b2989702 frodenas/postgresql:latest "/scripts/run.sh " 5 seconds ago Up 4 seconds 0.0.0.0:32769->5432/tcp happy_bell |
|
# 017f9ce7362d frodenas/postgresql:latest "/scripts/run.sh " 5 seconds ago Up 2 seconds 0.0.0.0:32772->5432/tcp cf-foobar |
|
|
|
require 'docker' |
|
|
|
Docker::Container.all.each do |container| |
|
config = container.json['Config'] |
|
host_config = container.json['HostConfig'] |
|
|
|
name = container.json['Name'] |
|
ports = container.json['NetworkSettings']['Ports'] |
|
volumes = container.json['Volumes'] |
|
|
|
new_container_options = config.merge({ |
|
'name' => name, |
|
}) |
|
start_container_options = host_config.merge({ |
|
'PortBindings' => ports, |
|
}) |
|
|
|
puts "Removing container #{name}" |
|
container.remove(force: true) |
|
puts "Recreating container #{name}" |
|
new_container = Docker::Container.create(new_container_options) |
|
puts "Restarting container #{name} with ports #{ports.inspect}" |
|
new_container.start(start_container_options) |
|
end |