- Docker and Kubernetes for Java Developers
- Jaroslaw Krochmalski
- 315字
- 2021-07-02 18:44:53
Connecting a container to the network
Now we have our myNetwork ready, we can run the Docker container and attach it to the network. To launch containers, we are going to user the docker run --net=<NETWORK> option, where the <NETWORK> is the name of one of the default networks or the one you have created yourself. Let's run Apache Tomcat for example, which is an open source implementation of the Java Servlet and JavaServer pages technologies:
docker run -it --net=myNetwork tomcat
It will take a while. The Docker engine will pull all of the Tomcat's image layers from the Docker Hub and then run the Tomcat container. There's another option to attach the network to the container, you can inform Docker that you would like the container to connect to the same network as other containers use. This way, instead of specifying a network explicitly, you just instruct Docker that you want two containers run on the same network. To do this, use the container: prefix, as in the following example:
docker run -it --net=bridge myTomcat docker run -it --net=container:myTomcat myPostgreSQL
In the previous example, we run the myTomcat image using the bridge network. The next command will run the myPostgreSQL image, using the same network as myTomcat uses. This is a very common scenario; your application will run on the same network as the database and this will allow them to communicate. Of course, the containers you launch into the same network must be run on the same Docker host. Each container in the network can directly communicate with other containers in the network. Though, the network itself isolates the containers from external networks, as seen in the following diagram:

If you run your containers in a bridge, isolated network, we need to instruct Docker on how to map the ports of our containers to the host's ports. We are going to do this now.
- Beginning Java Data Structures and Algorithms
- 數(shù)據(jù)結(jié)構(gòu)與算法分析(C++語言版)
- Web Development with MongoDB and Node(Third Edition)
- TypeScript 2.x By Example
- 算法設(shè)計與分析:基于C++編程語言的描述
- ASP.NET求職寶典
- Mastering Gephi Network Visualization
- Java EE 7 with GlassFish 4 Application Server
- IPython Interactive Computing and Visualization Cookbook
- UI設(shè)計基礎(chǔ)培訓(xùn)教程(全彩版)
- SAP Web Dynpro for ABAP開發(fā)技術(shù)詳解:基礎(chǔ)應(yīng)用
- JavaWeb從入門到精通(視頻實戰(zhàn)版)
- 深入理解Zabbix監(jiān)控系統(tǒng)
- 走近SDN/NFV
- Visual C++網(wǎng)絡(luò)編程教程(Visual Studio 2010平臺)