Docker/Boot2Docker: How to run multiple instances of a same container without port forwarding?

777 views Asked by At

I have a container that listens to port 8080. I want to spin up 3 instances of the same container on the same host without having to do port forwarding. I want to access each of the instances using a unique IP.

I am running Docker via Boot2Docker since I am running it on a Mac machine. I do not intend to run multiple instances of Boot2Docker as it is memory intensive.

The reason I do not want to do port forwarding is because my application is a distributed application. Each node in the cluster assumes that its peer is running on the same port.

1

There are 1 answers

2
BMW On

(Maybe there are better solutions within boot2docker.)

For a fast solution, I recommend to do this via Vagrant.

** review this document. https://coreos.com/docs/running-coreos/platforms/vagrant/

update config.rb file

config.rb

# Size of the CoreOS cluster created by Vagrant
$num_instances=3

** start vagrant with three CoreOS instances. Start the machine(s):

vagrant up

List the status of the running machines:

$ vagrant status
Current machine states:

core-01                   running (virtualbox)
core-02                   running (virtualbox)
core-03                   running (virtualbox)

This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.

** login each instance and start the docker container

docker pull <image>
docker run ...

Another way to do that is via Docker machine

Note: Machine is currently in beta, so things are likely to change. We don't recommend you use it in production yet.

Machine makes it really easy to create Docker hosts on your computer, on cloud providers and inside your own data center. It creates servers, installs Docker on them, then configures the Docker client to talk to them.

Relative document : https://docs.docker.com/machine/