hyperledger-labs / minifabric

Do fabric network the right and easy way.
Apache License 2.0
302 stars 166 forks source link

Question: Running Containers in Parallel Support (Docker PublishAllPorts: true) #105

Closed petermetz closed 3 years ago

petermetz commented 3 years ago

Can I use the docker image of MiniFabric to pull up multiple containers on the same host machine side by side by with PublishAllPorts enabled (which randomizes which host ports get mapped to the container's ports)?

This is a feature that's missing from Cactus' own Fabric AIO (all in one) image and so far the only way it seemed possible to achieve in that image if we did Docker in Docker (because the chain code peers need the fixed ports AFAIK).

Thank you in advance for the answers and apologies if this is somewhere in the documentation already!

litong01 commented 3 years ago

@petermetz Peter, I am not really sure I understand your question. Pull up multiple containers mean start up multiple docker containers? If so, minifabric does that already.

litong01 commented 3 years ago

@petermetz if your question is about if node port can be exposed to outside of the docker network (and the machine running these containers), the answer is -e true flag or you can even specify a starting port like -e 7300. Please give it a try and see how ports being allocated to each container and also see the generated connection profiles.

petermetz commented 3 years ago

Pull up multiple containers mean start up multiple docker containers? If so, minifabric does that already.

@litong01 Thank you for the response! That does sound great. To clarify, by saying pulling up multiple containers, you mean multiple distinct ledgers that are independent of each other and all listen on different ports, or do you just refer to the fact that on average a single Fabric ledger deployment consists of several different containers (orderer, ca, peers, etc.)?

@petermetz if your question is about if node port can be exposed to outside of the docker network (and the machine running these containers), the answer is -e true flag or you can even specify a starting port like -e 7300. Please give it a try and see how ports being allocated to each container and also see the generated connection profiles.

I think this may be it. Here's what I need to be able to do (in sort of a pseudo code manner because I don't know the exact syntax yet):

# First standalone Fabric ledger is now running and listens on port 7300
minifabric up -e 7300 

# ***Second*** standalone Fabric ledger is now running and listens on port 7301 
# (or any other available port that we can query at runtime to determine where the second ledger is listening)
minifabric up -e 7300 

The part about being able to get the dynamically allocated port information is important because we want to use this in automated tests so there won't be a human around to figure out who listens on what port manually and we also are trying to avoid having flaky tests. The second important part is that I passed in -e 7300 for both processes with which I intended to signify that we do not have the ability to choose an available port in advance and then pass that in, because dozens of other tests are also running in parallel and allocating randomized ports for testing purposes as well so collisions could always happen if we were to explicitly choose ports instead of letting the OS allocate one that we can than query (as in obtain the port number that was chosen).

I hope I'm making it clearer not the other way around, please do let me know if this doesn't make sense still. :-)

litong01 commented 3 years ago

minifabric can stand up a cluster of a node, or stand up just one node. Each peer can participate in many channels, a channel can be roughly understood a ledger. If a peer node only participate in one channel, then that peer only has one ledger.

minifab up -e 7300 basically means the starting port is 7300. how many nodes will be started completely depends on your spec.yaml file. Here is an example, https://github.com/hyperledger-labs/minifabric/blob/master/spec.yaml.

Please also read this doc to get more understanding of Minifabric. https://github.com/hyperledger-labs/minifabric/blob/master/docs/README.md

petermetz commented 3 years ago

Each peer can participate in many channels, a channel can be roughly understood a ledger.

Thanks @litong01 I'll consider that. For now we'd prefer to have the individual test cases control their set up/tear down logic independently of other tests and the tests themselves have to be runnable standalone too so it's not good for them to have the assumption baked in that a ledger is already pulled and a channel can be created.