providers/docker: expose ports
This commit is contained in:
parent
ff9de3586a
commit
c818a14072
|
@ -86,6 +86,7 @@ module VagrantPlugins
|
|||
cmd: @provider_config.cmd,
|
||||
detach: true,
|
||||
env: @provider_config.env,
|
||||
expose: @provider_config.expose,
|
||||
extra_args: @provider_config.create_args,
|
||||
hostname: @machine_config.vm.hostname,
|
||||
image: image,
|
||||
|
|
|
@ -22,6 +22,12 @@ module VagrantPlugins
|
|||
# @return [Hash]
|
||||
attr_accessor :env
|
||||
|
||||
# Ports to expose from the container but not to the host machine.
|
||||
# This is useful for links.
|
||||
#
|
||||
# @return [Array<Integer>]
|
||||
attr_accessor :expose
|
||||
|
||||
# Force using a proxy VM, even on Linux hosts.
|
||||
#
|
||||
# @return [Boolean]
|
||||
|
@ -71,6 +77,7 @@ module VagrantPlugins
|
|||
@cmd = UNSET_VALUE
|
||||
@create_args = []
|
||||
@env = {}
|
||||
@expose = []
|
||||
@force_host_vm = UNSET_VALUE
|
||||
@has_ssh = UNSET_VALUE
|
||||
@image = UNSET_VALUE
|
||||
|
@ -108,6 +115,10 @@ module VagrantPlugins
|
|||
env.merge!(other.env) if other.env
|
||||
result.env = env
|
||||
|
||||
expose = self.expose.dup
|
||||
expose += other.expose
|
||||
result.instance_variable_set(:@expose, expose)
|
||||
|
||||
links = _links.dup
|
||||
links += other._links
|
||||
result.instance_variable_set(:@links, links)
|
||||
|
@ -127,6 +138,8 @@ module VagrantPlugins
|
|||
@remains_running = true if @remains_running == UNSET_VALUE
|
||||
@vagrant_machine = nil if @vagrant_machine == UNSET_VALUE
|
||||
@vagrant_vagrantfile = nil if @vagrant_vagrantfile == UNSET_VALUE
|
||||
|
||||
@expose.uniq!
|
||||
end
|
||||
|
||||
def validate(machine)
|
||||
|
|
|
@ -33,10 +33,12 @@ module VagrantPlugins
|
|||
name = params.fetch(:name)
|
||||
cmd = Array(params.fetch(:cmd))
|
||||
env = params.fetch(:env)
|
||||
expose = Array(params[:expose])
|
||||
|
||||
run_cmd = %W(docker run --name #{name})
|
||||
run_cmd << "-d" if params[:detach]
|
||||
run_cmd += env.map { |k,v| ['-e', "#{k}=#{v}"] }
|
||||
run_cmd += expose.map { |p| ['--expose', "#{p}"] }
|
||||
run_cmd += links.map { |k, v| ['--link', "#{k}:#{v}"] }
|
||||
run_cmd += ports.map { |p| ['-p', p.to_s] }
|
||||
run_cmd += volumes.map { |v| ['-v', v.to_s] }
|
||||
|
|
|
@ -39,6 +39,7 @@ describe VagrantPlugins::DockerProvider::Config do
|
|||
before { subject.finalize! }
|
||||
|
||||
its(:build_dir) { should be_nil }
|
||||
its(:expose) { should eq([]) }
|
||||
its(:cmd) { should eq([]) }
|
||||
its(:env) { should eq({}) }
|
||||
its(:force_host_vm) { should be_false }
|
||||
|
@ -82,6 +83,20 @@ describe VagrantPlugins::DockerProvider::Config do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#expose" do
|
||||
before do
|
||||
valid_defaults
|
||||
end
|
||||
|
||||
it "uniqs the ports" do
|
||||
subject.expose = [1, 1, 4, 5]
|
||||
subject.finalize!
|
||||
assert_valid
|
||||
|
||||
expect(subject.expose).to eq([1, 4, 5])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#image" do
|
||||
it "should be valid if set" do
|
||||
subject.image = "foo"
|
||||
|
@ -166,6 +181,16 @@ describe VagrantPlugins::DockerProvider::Config do
|
|||
end
|
||||
end
|
||||
|
||||
context "exposed ports" do
|
||||
it "merges the exposed ports" do
|
||||
one.expose << 1234
|
||||
two.expose = [42, 54]
|
||||
|
||||
expect(subject.expose).to eq([
|
||||
1234, 42, 54])
|
||||
end
|
||||
end
|
||||
|
||||
context "links" do
|
||||
it "should merge the links" do
|
||||
one.link "foo"
|
||||
|
|
Loading…
Reference in New Issue