The first thing to check is whether there's a firewall or other network middlebox between wherever you're installing Discourse and the Internet, that could be getting in the way. If
bundle install is hanging, it almost certainly means that the container can't contact
rubygems.org to download the packages it needs.
Also, when you say "the network connection is lost", which connection do you mean? The complete log of the rebuild session, containing everything between the command start and termination, may show something that you don't realise is important, but has meaning to someone more experienced with diagnosing these problems. Finally, a complete description of the environment you're trying to run Discourse in (OS, hosting provider, etc) may be helpful.